DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Page 1 of 2 12 LastLast
Results 1 to 15 of 24

Thread: Need Help with my project

  1. #1
    Join Date
    Mar 2008
    Posts
    130

    Need Help with my project

    hi im here again..im making a project just a practice for me in visual basic..

    im making a simple ordering system...i dont have any database yet wat i have is a folder located at my application path where i automaticly creates a .txt document where infos are stored..my problem is how will i make my status bar in my main form show the name of the person who login..

    i have a folder Employees
    where the account are stored example

    john123.txt
    it contains this info:
    john123 < username
    12345 < passwrod
    john doe < cashier name


    how will i make "John Doe" appear on the label i made in the main window

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,663
    Is this what you mean?
    Code:
    Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
    (ByVal lpBuffer As String, _
    nSize As Long) As Long
    
    Private UserAccount As String
    
    Private Sub GetUserAccount()
    
        Dim sBuffer As String
        Dim lSize As Long
        
        sBuffer = Space$(255)
        lSize = Len(sBuffer)
        Call GetUserName(sBuffer, lSize)
        If lSize > 0 Then
            UserAccount = Left$(sBuffer, lSize - 1)
        Else
            UserAccount = vbNullString
        End If
        
    End Sub

  3. #3
    Join Date
    Mar 2008
    Posts
    130
    hello hack remember me?

    hmp..im currenty studying visual basic again..

    i didnt understand the codes you posted..can you guide me throught

    what is need is make this label show the name of the person who login..

  4. #4
    Join Date
    Mar 2008
    Location
    Lancashire, UK
    Posts
    156
    I think he wants to load that data from the file, and display the bottom name. (John Doe)

    Try this
    Code:
    Dim sLine As String, FilePath As String
    Dim F As Integer
    
    Dim UserName As String, Password As String, CashierName As String
    
    
    FilePath = App.Path & "\john123.txt" 'Make the path of the file
    F = FreeFile() 'Find a file number that we can use
    
    Open FilePath For Input As #F 'Open the file
        Line Input #F, sLine 'Get the first line of the file
        UserName = sLine 'Set username to the first line
        
        Line Input #F, sLine 'Get the second line
        Password = sLine 'Set the password to the second line
        
        Line Input #F, sLine 'Get the third line
        CashierName = sLine 'Set the cashiername to the third line
        
    Close #F 'Close the file
    
    StatusBar1.Panels(0).Text = CashierName 'Set the statusbar's first panel text to the cashier's name

  5. #5
    Join Date
    Mar 2008
    Posts
    130
    how will i pass the info from my login window where my user logged and passed it to my main window...

    like
    if john123 logged i want to pass the info john123 to my main window so i can open the its info in my account folder and let his name show up in my label

  6. #6
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,663
    Code:
    Private Sub Form_Load()
    GetUserAccount
    Label1.Caption = UserAccount
    End Sub

  7. #7
    Join Date
    Mar 2008
    Posts
    130
    GetUserAccount
    whats this?

    here is my code at my login form
    Private Sub Command1_Click()

    End Sub

    Private Sub cmdLogIN_Click()
    Dim openfile As String
    Dim datafile As String

    openfile = txtUser.Text
    datafile = txtPass.Text

    If txtUser.Text = "" Then
    MsgBox "Please enter Username"
    Else
    If txtPass.Text = "" Then
    MsgBox "Please enter Password"
    Else
    Open App.Path & "\Account\Employee\" + openfile + ".txt" For Input As #2

    Input #2, openfile
    If txtUser.Text = openfile Then
    Input #2, datafile
    If txtPass.Text = datafile Then
    frmMain.Show
    Me.Hide
    Else
    MsgBox "Wrong Password"
    End If
    End If
    Close #2
    End If
    End If

    End Sub
    here is in my main form
    Private Sub cmbPlate_Change()

    End Sub

    Private Sub Form_Load()
    cmbType.AddItem "Car"
    cmbType.AddItem "Motorcycle"

    Get
    lblName.Caption = UserAccount

    End Sub

    Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single)

    End Sub

    Private Sub mnuDataNewEmployee_Click()
    frmReg.Show
    End Sub

    Private Sub mnuFileExit_Click()
    End
    End Sub

    Private Sub mnuFileLogOut_Click()
    frmLogin.Show
    Me.Hide

    End Sub

  8. #8
    Join Date
    Mar 2008
    Posts
    130
    so how will i get the info that has been entered in my txtUser

  9. #9
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,663
    Quote Originally Posted by chokies12
    so how will i get the info that has been entered in my txtUser
    What do you mean by "get the info"?

    Are you asking how to save what is in the textbox back to a text file?

  10. #10
    Join Date
    Mar 2008
    Posts
    130
    how will i pass the username entered in my textbox named txtUser to my main window ?

    is it

    GettxtUser?
    but i think it wont work because it will just find txtUser in my main window and will return an error but theres no textbox containing that name..because txtUser is in a different form

  11. #11
    Join Date
    Mar 2008
    Location
    Lancashire, UK
    Posts
    156
    In your login form
    Code:
    Public CashierName As String
    
    Private Sub cmdLogIN_Click()
    Dim openfile As String
    Dim datafile As String
    
    openfile = txtUser.Text
    datafile = txtPass.Text
    
    If txtUser.Text = "" Then
        MsgBox "Please enter Username"
    Else
        If txtPass.Text = "" Then
            MsgBox "Please enter Password"
        Else
            Open App.Path & "\Account\Employee\" + openfile + ".txt" For Input As #2
            
            Input #2, openfile
            
            If txtUser.Text = openfile Then
                Input #2, datafile
                If txtPass.Text = datafile Then
                    
                    Input #2, CashierName
                    'This will set cashiername (at the top) to the name of the cashier in the file
                    
                    frmMain.Show
                    Me.Hide
                    
                Else
                    MsgBox "Wrong Password"
                End If
            End If
            
        Close #2
        End If
    End If
    
    End Sub
    This will get the 3rd line of the textfile, which is where the cashier's name is, from what you said.

    Then in frmMain
    Code:
    Private Sub Form_Load()
    cmbType.AddItem "Car"
    cmbType.AddItem "Motorcycle"
    
    
    lblName.Caption = frmLogin.CashierName
    
    End Sub

    Sorry if i'm confusing your with Hack's soloution. Hack's soloution will find out the username of the computer, and set lblName's caption to that.
    Mine will get the third line of the textfile, and set lblName's caption to that.

  12. #12
    Join Date
    Mar 2008
    Posts
    130
    ohh there you go i thanks..all i need is the logic.. so i just need to declare my frmlogin in the frmmain..hehe thanks ill start to work from here..

    thanks CptNeutral and Hack
    be back if i encounter any problems with this

  13. #13
    Join Date
    Mar 2008
    Posts
    130
    frmLogin.CashierName doesnt work...

  14. #14
    Join Date
    Mar 2008
    Location
    Lancashire, UK
    Posts
    156
    What's your login form called?
    If it's called Form1, then use
    Code:
    Form1.CashierName

  15. #15
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,663
    Quote Originally Posted by chokies12
    frmLogin.CashierName doesnt work...
    Stating that means nothing. What does "doesn't work" mean? Are you getting an error? If so, what is the error?

Similar Threads

  1. Control Arrays in VB.NET
    By Gary Nelson in forum .NET
    Replies: 277
    Last Post: 10-01-2003, 12:00 AM
  2. Good Editorial by Russell Jones
    By Robert G in forum .NET
    Replies: 84
    Last Post: 02-08-2001, 03:38 PM
  3. Replies: 0
    Last Post: 09-13-2000, 10:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center