LITTLEBLACKDOG.COM Forum Index LITTLEBLACKDOG.COM

 
LWD LWD   FAQ FAQ   Memberlist Memberlist   Usergroups Usergroups   Active Topics Active Topics   Register Register  
  Profile Profile   Log in to check your private messages Log in to check your private messages   Log in Log in  
  Who is Online Who is Online   Image Gallery Image Gallery   Chat Chat   Search Search  
  LWDGear       LBDGear  

View next topic
View previous topic
Post new topic     Reply to topic   LITTLEBLACKDOG.COM Forum Index » Code Warriors
Author Message
Daftlad
Stray Dog


Joined: 14 Oct 2003
Posts: 7
Location: England

Post Posted: Fri Oct 24, 2003 5:59 am   Post subject: Sorry to bother you all again :D New Problem in VB :D Reply with quote Back to top  

Thanks for all the help so far ! u see the force isnt very strong with me amd I'm just bumbing into problems all over the place Very Happy

Well this time I'm trying to use a varible I have declared as public in a module in a form but its just not letting me or at least its not giving me the right value ! is there anything I should be aware of when dealing with passing and using varibles in separate forms !

thank u ! Soon I might even be able to help someone else hahah

_________________
"Its not the size of the wand, its the magic in the stick.."
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
Webster
Guide Dog
Guide Dog


Joined: 16 Feb 2002
Age: 28
Posts: 8701
Location: Vacationland

Post Posted: Fri Oct 24, 2003 6:54 am   Post subject: Re: Sorry to bother you all again :D New Problem in VB :D Reply with quote Back to top  

Daftlad wrote:
Thanks for all the help so far ! u see the force isnt very strong with me amd I'm just bumbing into problems all over the place Very Happy

Well this time I'm trying to use a varible I have declared as public in a module in a form but its just not letting me or at least its not giving me the right value ! is there anything I should be aware of when dealing with passing and using varibles in separate forms !

thank u ! Soon I might even be able to help someone else hahah


Did you declare it correctly? Are there any typos? Are you using option explicit? Have you redeclared that variable in a more local scope? Are you using the value of the variable or the reference to it?

_________________
www .Run To Win.com
The Marathon Thread
I finally published my book: Comprehensive Guide to Marathon Preparation & Recovery
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Lycander
Lead Dog
Lead Dog


Joined: 24 May 2002
Age: 25
Posts: 12198
Location: The Constitution State

Post Posted: Fri Oct 24, 2003 7:14 am   Post subject: Reply with quote Back to top  

I haven't used VB in years so bare with me.

My guess is that variables you declare in forms/modules are only visible within the scope of that object. Remember what I had said about functions? They can return values. So in your forms/modules write functions that will read/write values into those variables.

From "form1" you can refer to a function in "form2". I think it's something like
Code: Select all

Call form2.functionName()


Quick example:

Form2 code:
Code: Select all

Dim var2 As String

Private Sub Form_Load()
    var2 = "Hello World"
End Sub

Public Function getVar() As String
     'the format for returning a value from a function is [function name] = [expression]
    getVar = var2
End Function


Form1 code:
Code: Select all

Dim var1

Private Sub Command1_Click()
    Set var1 = Form2.getVar
End Sub


The idea is, if you can't make variables public and accessible to other forms/modules, then functions is a good fallback because functions can be made public and accessible to other forms/modules. So then just write functions that return the desired variable's value.
View user's profile Send private message
Webster
Guide Dog
Guide Dog


Joined: 16 Feb 2002
Age: 28
Posts: 8701
Location: Vacationland

Post Posted: Fri Oct 24, 2003 8:18 am   Post subject: Reply with quote Back to top  

Quote:
I have declared as public in a module in a form


I may have misread that originally...or I may not have. I went back and looked after reading Lycander's response and now I'm not so sure.

I assumed that you meant you added a module to the project and declared it global there (which should work the way you seem to want it to). This would have created a .bas file.

However, your comment about the module being in the form is confusing, since if you declared it public or global in the form then it would still have to have an explicit reference from another form (as Lycander pointed out).

_________________
www .Run To Win.com
The Marathon Thread
I finally published my book: Comprehensive Guide to Marathon Preparation & Recovery
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Daftlad
Stray Dog


Joined: 14 Oct 2003
Posts: 7
Location: England

Post Posted: Mon Oct 27, 2003 3:14 am   Post subject: Reply with quote Back to top  

here is the code I have written so far and i'M still having the same problemn passing varibles ! Sad thanks for the help tho Very Happy

MODULE1
Quote:
Private MNumber As Integer
Private CNumber As String

Public Sub ListMaker(MNumber, RNumber)

Dim ListWriter As Integer
Dim ListItem As String
Dim MachineWriter As String

ListWriter = 0

FrmSelectRoom.LstMachines.Clear

For ListWriter = 1 To MNumber

ListItem = ""
MachineWriter = ListWriter

If Len(MachineWriter) < 2 Then MachineWriter = "0" & MachineWriter

ListItem = RNumber & "-" & MachineWriter
FrmSelectRoom.LstMachines.AddItem ListItem

Next ListWriter

End Sub



FRMSELECTROOM
Quote:

Dim CaseTest As String
Dim NumberofMachines As Integer
Dim RoomNumber As String

CaseTest = LstRooms.Text

Select Case CaseTest

Case Is = "C4"
NumberofMachines = 25
RoomNumber = "C4"
Call ListMaker(NumberofMachines, RoomNumber)

Case Is = "C5"
NumberofMachines = 24
RoomNumber = "C5"
Call ListMaker(NumberofMachines, RoomNumber)

Case Is = "B15"
NumberofMachines = 23
RoomNumber = "B15"
Call ListMaker(NumberofMachines, RoomNumber)

Case Is = "IT"
LstMachines.Clear
LstMachines.AddItem "IT-01"
LstMachines.AddItem "IT-02"
LstMachines.AddItem "IT-03"

End Select

End Sub

Public Function GetCompName() As String
GetCompName = CompName
End Function



FRMCREATEMESSAGE
Quote:
Private CompName As String

Private Sub Command1_Click()
Set CompName = FrmSelectRoom.GetCompName
MsgBox (ComputerName)
End Sub

Private Sub Form_Load()
FraCreate.Caption = "Create a Message for " & CompName
End Sub



can any one help ?? I'm losing lol

_________________
"Its not the size of the wand, its the magic in the stick.."
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
EdisonRex
Lead Dog
Lead Dog


Joined: 06 May 2002
Posts: 10154
Location: Not Moscow

Post Posted: Mon Oct 27, 2003 4:11 am   Post subject: Reply with quote Back to top  

off the top of my head it looks like the second parameter wants to be declared a string. You don't declare it at all and that makes it an integer.

_________________
Garret: It's so retro.
EGM: What does retro mean to you?
Parker: Like, old and outdated.
View user's profile Send private message AIM Address Yahoo Messenger
Lycander
Lead Dog
Lead Dog


Joined: 24 May 2002
Age: 25
Posts: 12198
Location: The Constitution State

Post Posted: Mon Oct 27, 2003 6:47 am   Post subject: Reply with quote Back to top  

In "FRMSELECTROOM" in the function

Public Function GetCompName() As String
GetCompName = CompName
End Function

You haven't specified what CompName equals within that form.
View user's profile Send private message
Display posts from previous:   
Post new topic     Reply to topic

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group
phpBB SEO
All times are GMT - 8 Hours

Help us keep advertisements off this site. Donate today!