Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default VBA passing information between differnt User Forms

Hi u,

the task is as following :

When User Form1 (UF1) is called, it checks for a value in a Sheet. If
the value isn't set UF1 croaks and sets a flag to be passed to a
UserForm (UF2) where the value is to be set.

Searching 4 the solution I found Public Properties the most suitable
way solving my task. But i didn't got the string yet. In UF2 the
flagRogue keeps empty.

Due to what I found I tried following:

in: UF1
'---------------
private flagRogue as string
publicproperty get flagStatus() as String
flagStatus = flagCroak
end property
publicproperty let flagStatus(byval flagVal as String)
flagStatus = flagRogue
end property
'--------------
' Initialize:
dim wannaSthg as new UF2
...
if <no Value Then
<croak
flagRogue = 1
wannaSthg.flagRogue = Me.flagRogue
wannaSthg.Show
end if


in UF2
'-------------
private flagRogue as string
publicproperty get flagStatus() as String
flagStatus = flagCroak
end property
publicproperty let flagStatus(byval flagVal as String)
flagStatus = flagRogue
end property
'--------------
' Initialize:
dim wannaSthg as new UF2
...
if flagRogue Then
<do something
else
<do something else
end if

Question:
Where I'm wrong ???

thanx 4 helping
VBR

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default VBA passing information between differnt User Forms

It would be far simpler to create the flag variable as a Public variable in
a general code module, you will then be able to load and read it from either
form.

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"chfa" wrote in message
ups.com...
Hi u,

the task is as following :

When User Form1 (UF1) is called, it checks for a value in a Sheet. If
the value isn't set UF1 croaks and sets a flag to be passed to a
UserForm (UF2) where the value is to be set.

Searching 4 the solution I found Public Properties the most suitable
way solving my task. But i didn't got the string yet. In UF2 the
flagRogue keeps empty.

Due to what I found I tried following:

in: UF1
'---------------
private flagRogue as string
publicproperty get flagStatus() as String
flagStatus = flagCroak
end property
publicproperty let flagStatus(byval flagVal as String)
flagStatus = flagRogue
end property
'--------------
' Initialize:
dim wannaSthg as new UF2
..
if <no Value Then
<croak
flagRogue = 1
wannaSthg.flagRogue = Me.flagRogue
wannaSthg.Show
end if


in UF2
'-------------
private flagRogue as string
publicproperty get flagStatus() as String
flagStatus = flagCroak
end property
publicproperty let flagStatus(byval flagVal as String)
flagStatus = flagRogue
end property
'--------------
' Initialize:
dim wannaSthg as new UF2
..
if flagRogue Then
<do something
else
<do something else
end if

Question:
Where I'm wrong ???

thanx 4 helping
VBR



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 120
Default VBA passing information between differnt User Forms

Not sure i understand exactly what you're doing but it looks like your
variable isn't being passed between the forms try in UF2 if you
haven't unloaded UF1

UF2_Initialize()

UF2.flagRogue.value = UF1.flagRogue.value

end sub

Personally i prefer using global variable as you're not dependant on
userform life.

HTH

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default VBA passing information between differnt User Forms

I'd check for the value in the code that calls UF1. If no value, skip UF1
and call UF2.

Despite what my colleagues say, I find it safer to use properties than
globals. However, I don't think you're using the property correctly. This is
not clear and probably wrong:

'---------------
private flagRogue as string
publicproperty get flagStatus() as String
flagStatus = flagCroak
end property
publicproperty let flagStatus(byval flagVal as String)
flagStatus = flagRogue
end property
'--------------

I suppose you want to do this:

'---------------
' module level variable
private m_flagRogue as string

public property get flagStatus() as String
' return value stored in module level variable
flagStatus = m_flagRogue
end property

public property let flagStatus(byval flagVal as String)
' assign input value to module level variable
m_flagRogue = flagVal
end property
'--------------

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"chfa" wrote in message
ups.com...
Hi u,

the task is as following :

When User Form1 (UF1) is called, it checks for a value in a Sheet. If
the value isn't set UF1 croaks and sets a flag to be passed to a
UserForm (UF2) where the value is to be set.

Searching 4 the solution I found Public Properties the most suitable
way solving my task. But i didn't got the string yet. In UF2 the
flagRogue keeps empty.

Due to what I found I tried following:

in: UF1
'---------------
private flagRogue as string
publicproperty get flagStatus() as String
flagStatus = flagCroak
end property
publicproperty let flagStatus(byval flagVal as String)
flagStatus = flagRogue
end property
'--------------
' Initialize:
dim wannaSthg as new UF2
..
if <no Value Then
<croak
flagRogue = 1
wannaSthg.flagRogue = Me.flagRogue
wannaSthg.Show
end if


in UF2
'-------------
private flagRogue as string
publicproperty get flagStatus() as String
flagStatus = flagCroak
end property
publicproperty let flagStatus(byval flagVal as String)
flagStatus = flagRogue
end property
'--------------
' Initialize:
dim wannaSthg as new UF2
..
if flagRogue Then
<do something
else
<do something else
end if

Question:
Where I'm wrong ???

thanx 4 helping
VBR



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default VBA passing information between differnt User Forms


Hi John,

thank u 4 your answer. Of course theres no point
in using global variables. That's a kind of dirty hacking ;-).

Your hint signing the variables with "m_" seems a
valuable practice worth adopting.

But last not least. The knack of the problem is covered
in Keith75's comment. Using UF<Nbr_Intialize
runs into a deadlock, as each module tries to initialize
the variables .... Using UF<nbr_Activate works.

And by the way. Why String? Ok. That's a historical
try. I changed to boolean, the most suitable Type for
this kind passing states.

Thanx a lot, happy easter, so long, vbr

chfa






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default VBA passing information between differnt User Forms



"chfa" wrote in message
oups.com...


thank u 4 your answer. Of course theres no point
in using global variables. That's a kind of dirty hacking ;-).



Why?


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default VBA passing information between differnt User Forms


.... Of course theres no point
in using global variables. That's a kind of dirty hacking ;-).


Why?


at first of all VBA is object orientated.
at second, far more important, it's far easier for maintenance
and understanding the structure of the code if global variables
are not used. So there are only the interfaces as the gates
for the datas beeing handed over.

and atleast: backdoors, as i regard globals, are something
suspicious ;-))

(:
ChFa

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing a Forms Control to Function Pflugs Excel Programming 5 August 24th 06 10:34 PM
passing variables between 2 forms burl_rfc Excel Programming 3 April 14th 06 05:49 AM
Passing variables between forms Sami82[_8_] Excel Programming 7 October 8th 05 12:12 AM
Why is the information on preview screen differnt than on normal . kaylaaj Excel Worksheet Functions 1 March 17th 05 06:03 PM
User Forms - passing data between them mickiedevries Excel Programming 3 June 21st 04 08:59 PM


All times are GMT +1. The time now is 10:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"