Staredit Network

Staredit Network -> Miscellaneous -> VB Help Needed
Report, edit, etc...Posted by LegacyWeapon on 2005-03-17 at 20:25:20
CODE
Private Sub Command5_Click()
Close #1
Open path & "\sample.txt" For Output As #1
intMsg = MsgBox("File " & path & "\sample.txt opened")
Print #1, List1.Text
intMsg = MsgBox("Writing list to sample.txt ")
End Sub


All this did was make whatever I was selecting from the list saved into the sample.txt and not the ENTIRE list.

I know I just started pinch.gif
Report, edit, etc...Posted by RexyRex on 2005-03-17 at 20:39:45
Does VB use ";" ?
Report, edit, etc...Posted by LegacyWeapon on 2005-03-17 at 20:42:02
No.

Here's the rest of the programming if you want to see it wink.gif
CODE
Dim studentName As String
Dim num As Integer
Dim eraser As Integer
Dim path As String
Dim printer As TextBox

Private Sub add_name()
studentName = InputBox("Enter Item", "Yea...", "")
List1.AddItem studentName
End Sub

Private Sub Command1_Click()
add_name
End Sub

Private Sub Command2_Click()
End
End Sub

Private Sub Command3_Click()
If List1.ListCount > eraser Then
If List1.ListCount <> 0 Then
List1.RemoveItem (eraser)
End If
End If
End Sub

Private Sub Command5_Click()
Open path & "\sample.txt" For Output As #1
intMsg = MsgBox("File " & path & "\sample.txt opened")
Print #1, List1.Text
intMsg = MsgBox("Writing list to sample.txt ")
Close #1
End Sub

Private Sub Dir1_Change()
path = Dir1.path
End Sub

Private Sub Drive1_Change()
path = Dir1.path
End Sub

Private Sub List1_Click()
eraser = List1.ListIndex
End Sub
Report, edit, etc...Posted by chuiu on 2005-03-17 at 21:38:35
It needs to be something like:

CODE
For x = 0 to list1.listcount - 1
    Print #1, List1.index(x)
                OR
    Print #1, List1.listindex(x)
next x


I'm not sure which one it is and I don't have my MSDN libraries installed to look it up. But it should be one of those two.
Report, edit, etc...Posted by LegacyWeapon on 2005-03-17 at 22:26:29
I've tried that and I just did again to make sure but it doesn't work pinch.gif

It says
QUOTE
Compile error:

Wrong number of arguments or invalid property assignment


ADDITION:
Quick question while this topic is still here:
Is there any way to prevent crashing when trying to browse a drive without a disk in it? (Ex. A:\)
Report, edit, etc...Posted by chuiu on 2005-03-17 at 23:14:35
Sorry, its actually list (I just tested).

CODE
For x = 0 to list1.listcount - 1
   Print #1, List1.list(x)
next x


And I've never experienced crashing when going into a drive with no disk in it. Are you sure that is what is causing the crash?
Report, edit, etc...Posted by LegacyWeapon on 2005-03-18 at 14:42:34
Thank you so much Chu!

Now I have another question. How would you load up a file into a list where each space is one item in the list?
Report, edit, etc...Posted by LegacyWeapon on 2005-03-18 at 19:40:00
Ok everything is fixed thanks to Heimdal!

How do you focus on an item in a list?
Report, edit, etc...Posted by chuiu on 2005-03-18 at 21:10:59
CODE
List1.ListIndex = intX
Report, edit, etc...Posted by LegacyWeapon on 2005-03-18 at 21:53:01
Wow, I feel really stupid now.

And worse because I can't figure out how to do a linebreak when displaying a msgbox.

Edit - Or how to work this
CODE
On Error GoTo <label>

Edit2 - BTW, Thank you so much Chu for actually helping me out so much happy.gif. I plan on using this knowledge to program bigger stuff later on. Right now I'm making a very simple program that is basically useless but I keep building up on it anyways. This will help me build up my knowledge smile.gif
Report, edit, etc...Posted by chuiu on 2005-03-18 at 22:13:47
CODE
On Error goto ErrorHandler
'fast forward to end of module/function
Exit Sub

ErrorHandler:
'insert your code
end sub


As for your break, you cannot do 2 things at once so it has to happen after the msgbox. No problem, I know quite a bit about VB because I took 2 courses of it. Though don't ask me about Databases, I can work with them but I really hate doing so. smile.gif
Next Page (1)