Modules

Mumscake
04-09-2004, 03:36 PM
Just need some basic help how to use variables in 2 form:s. I know it has something to do with Modules, but i don't get it to work.

Lets say i got a variable on form4 and want it to work in form5, what shall i write.

Iceplug
04-09-2004, 05:15 PM
Declare a Public Shared variable in your form class.
You can access it from either form by using the name of the form, a dot, and then the name of the variable:
Form4.MyVariable.

Mumscake
04-09-2004, 05:30 PM
hmm k. Could you explain how to add a list to a txt file aswell

Ive written
Open "c:\hello.txt" For Output As #1
For i = 0 To 9
but dont know what to write next.

Iceplug
04-09-2004, 05:36 PM
That's VB6 code:
In .NET, you ought to make a StreamWriter
Dim SW As System.IO.StreamWriter = New System.IO.StreamWriter(path, append)

where you put True for append if you want the original file contents to be preserved.

To get data from the listbox, use:
ListBox.Items(i)
You'll probably need to convert the stuff you get back to String with .ToString()
or Convert.ToString(). :)

Mumscake
04-09-2004, 05:43 PM
ah, guess im on the wrong forum then :)
I've only been proramming for about a month in vb6, so obviously, i dont get that much from that steam thing

are u sure u dont know the vb6 code? :)

Iceplug
04-09-2004, 05:45 PM
I can't see how so many people go into the .NET forum when they only use VB6 ... okay enough ranting from me ... back to the topic ;)
In VB6, Open the File for Append instead of Output and
use the ListBox.List(i) inside the For Loop...
and to write to the file:
Print #1, ListBox.List(i)
:).

Mumscake
04-09-2004, 06:00 PM
oki thx :D

Ah, now i c why they write the same thing, never got what .NET was before :P

:huh: Mumscake :huh:

Mumscake
04-09-2004, 06:26 PM
1 more thing, if i wanna "imput" how do i write then? :)

Ive written,

Open "c:\hej.txt" For Input As #1
For i = 0 To 9
Print #1, List1.List(i)
Next i
Close #1
End Sub


Print #1, List1.List(i)<- gets yellow

Mumscake
04-09-2004, 06:52 PM
and how does the command loop works?

Iceplug
04-09-2004, 07:19 PM
#1:You use Input instead of Print :p

#2:What command Loop? You mean the keyword 'Loop'? in
Do
...
Loop
That marks the end of a Do Loop. :)

You can look in your MSDN for quick hints on syntax like this.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum