| Author |
Message |
Daftlad
Stray Dog

Joined: 14 Oct 2003 Posts: 7
Location: England
|
Posted:
Fri Oct 24, 2003 5:59 am Post subject: Sorry to bother you all again :D New Problem in VB :D |
|
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
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.."
|
|
|
|
|
Webster
Guide Dog


Joined: 16 Feb 2002 Age: 28 Posts: 8701
Location: Vacationland
|
Posted:
Fri Oct 24, 2003 6:54 am Post subject: Re: Sorry to bother you all again :D New Problem in VB :D |
|
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
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
|
|
|
|
|
Lycander
Lead Dog


Joined: 24 May 2002 Age: 25 Posts: 12198
Location: The Constitution State
|
Posted:
Fri Oct 24, 2003 7:14 am Post subject: |
|
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
Call form2.functionName()
Quick example:
Form2 code:
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:
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. |
|
|
|
|
|
|
Webster
Guide Dog


Joined: 16 Feb 2002 Age: 28 Posts: 8701
Location: Vacationland
|
Posted:
Fri Oct 24, 2003 8:18 am Post subject: |
|
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
|
|
|
|
|
Daftlad
Stray Dog

Joined: 14 Oct 2003 Posts: 7
Location: England
|
Posted:
Mon Oct 27, 2003 3:14 am Post subject: |
|
here is the code I have written so far and i'M still having the same problemn passing varibles ! thanks for the help tho
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.."
|
|
|
|
|
EdisonRex
Lead Dog


Joined: 06 May 2002 Posts: 10156
Location: Not Moscow
|
Posted:
Mon Oct 27, 2003 4:11 am Post subject: |
|
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.
|
|
|
|
|
Lycander
Lead Dog


Joined: 24 May 2002 Age: 25 Posts: 12198
Location: The Constitution State
|
Posted:
Mon Oct 27, 2003 6:47 am Post subject: |
|
In "FRMSELECTROOM" in the function
Public Function GetCompName() As String
GetCompName = CompName
End Function
You haven't specified what CompName equals within that form. |
|
|
|
|
|
|
|
|