View Full Version : Help me with my program plz
shaunchilling
04-01-04, 10:17 AM
im trying to learn vb programming so i have made a little program but i have got stuck.
My program has been made so you can register and have a user name. ive figgured all the form for the name boxes and stuff. but i cant figgure how to store the infomation.
someone please help
My code for the forms are:
form1
Private Sub Command1_Click()
Me.Hide
step2.Show
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Text2_Change()
End Sub
Private Sub Text3_Change()
End Sub
Form2
Private Sub Command1_Click()
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Text1_Change()
End Sub
Private Sub Text2_Change()
End Sub
shaunchilling
04-03-04, 07:05 AM
right let me make this easyer question ok. right i have a form with two text boxes in. And i want to know how do i save the text in to a file. ok
Create a Form with one CommandButton called cmdSave and one TextBox called txtContents. Add the code below to the form.
Option Explicit
Private Function SaveFile( myFile As String, fContents As Strng )
Open myFile for Output As #1
Print #1, fContents
Close #1
End Sub
Private Sub cmdSave_Click()
Dim sContents As String
Dim sFile As String
sContents = txtContents.text
sFile = "c:\myfile.txt"
SaveFile sFile, sContents
End Sub
This should give you an idea on how saving a file works. You should be able to get it right from here.
dazz417
04-30-04, 10:19 AM
im trying to learn vb programming so i have made a little program but i have got stuck.
My program has been made so you can register and have a user name. ive figgured all the form for the name boxes and stuff. but i cant figgure how to store the infomation.
someone please help
End Sub
just finished using this with my project. Requires a reference to the FileSystemObject and automatically creates the file if it doesn't exist, and the presence of control array of 3 textboxes.
Hope this helps
Option Explicit
Dim objSystem As FileSystemObject
Dim objText As TextStream
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdOK_Click()
Dim strUserID As String
Dim strPw As String, strCfmPw As String
Dim i As Integer
For i = 0 To 2
If txtUser(i).Text = "" Then
MsgBox "Value required", vbCritical
Beep
txtUser(i).SetFocus
Exit Sub
End If
Next i
strUserID = txtUser(0).Text
strPw = txtUser(1).Text
strCfmPw = txtUser(2).Text
If strPw <> strCfmPw Then
MsgBox "Please Re-enter the PassWord"
txtUser(1).Text = ""
txtUser(2).Text = ""
Exit Sub
Else
SaveUser strUserID, strPw
End If
Unload Me
End Sub
Sub SaveUser(UserID As String, Pword As String)
Dim Temp As String
Temp = UserID & ";" & Pword
If Not objSystem.FileExists("pword.cot") Then
Set objText = objSystem.OpenTextFile("pword.cot", ForAppending, True, TristateFalse)
objText.WriteLine "Administrator;1234"
objText.Close
Set objText = Nothing
End If
Set objText = objSystem.OpenTextFile("pword.cot", ForAppending, _ False, TristateFalse)
objText.WriteLine Temp
objText.Close
End Sub
Private Sub Form_Load()
Set objSystem = New FileSystemObject
End Sub
vBulletin® v3.6.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.