I've been at this for a few days, not making any progress, so I'm asking for help.

I have an application you log into based on an ID number (example 45)

In the app, there is a label. By default is has "lblID" in it, when when you log in, the 45 goes there (comes from MySQL)

I need to create a new folder on startup, and that folder needs to be named according to that ID number.

The problem I'm running into , is when the application starts, it creates the folder just fine, but it never names it according to the ID. It always names it lblID.

The code to create the folder is in the frmLoad-

x.CreateIDfolder()

Then it goes to the code in a module-

Public Sub CreateIDfolder()
        ' Create the officers folder based on his ID number
        ' This is for the new version, a new multi-user application.
        If Not Directory.Exists(myOfficerIDFolder) Then
            Directory.CreateDirectory(myOfficerIDFolder)
        End If
        ' Move current files into the new folder- the log files based on year.
    End Sub

Then in the same module, it creates the name from the ID number (or so it should)

Public myFilesFolder As String = myAppDataFolder & "Files\"
    Public myOfficerIDFolder As String = myFilesFolder & "" & frmMain.lblID.Text & ""

So as I mentioned, the folder is always lblID. Where am I going wrong?

Recommended Answers

All 15 Replies

Where you call

x.CreateIDfolder()

please provide full code...

Public Sub CreateIDfolder()
        ' Create the officers folder based on his ID number
        ' This is for the new version, a new multi-user application.
        If Not Directory.Exists(myOfficerIDFolder) Then
            Directory.CreateDirectory(myOfficerIDFolder)
        End If
        ' Move current files into the new folder- the log files based on year.
    End Sub

I was wondering if it was an issue with the order these things were loading. So I put the CreateIDfolder on a button, and clicked it long after the label populated with the ID number. It didn't matter. It created a folder called lblID.

This is the definition not call...


I mean where you use x.CreateIDfolder().

In form load event or somewhere else??

commented: Thanks for your time! +3

Yes, it's in frmLoad.

Public myFilesFolder As String = myAppDataFolder & "Files\"
    Public myOfficerIDFolder As String = myFilesFolder & "" & frmMain.lblID.Text & ""

Initialize these variables using database...

before calling x.CreateIDfolder()

Thanks- tried that. I put the x.CreateIDfolder() on a button and called it well after the DB variables loaded. Didn't work. Is that what you mean?

please post your full code so i can help you...

K, starts out here (stripped all the useless code not needed)

Public Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        ' Create the new folder on officer ID for the new multi user app
        x.CreateIDfolder()

    End Sub

x.vb is a module that contains a ton of variables.

This is in x.vb

Public Sub CreateIDfolder()
        ' Create the officers folder based on his ID number
        ' This is for the new version, a new multi-user application.
        If Not Directory.Exists(myOfficerIDFolder) Then
            Directory.CreateDirectory(myOfficerIDFolder)
        End If
        ' Move current files into the new folder- the log files based on year.
    End Sub

Also in x.vb, is the myOfficerIDFolder part.

Public myFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) & "\DailyLog\" '  Main Directory in Program Files"
    Public myAppDataFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "\DailyLog\" '  Main Directory in App Data

 ' ------------- FILES Folder FILES
    Public myFilesFolder As String = myAppDataFolder & "Files\"
    Public myOfficerIDFolder As String = myFilesFolder & "" & frmMain.lblID.Text & ""

So, in short, the file based on the ID is inside the Files folder in the application data.

Possibly silly question, but if you are creating the folder in the form load handler, then how can you have access to the ID number used to log in? I would assume that the user would have to log in first, and the log in area would not be available to the user until after the form load event has completed. In which case, you should create the folder just following the code that handles a successful log in.

Follow-up possibly silly question. What is the "x" in x.CreateIDfolder()? It's late here and my brain may have preceded my body to sleep.

No silly questions, they don't exist :)

There is a login form that loads first. Once that authenticates, the frmMain loads. When frmMain loads, it's pulling the info from the DB.

I agree with you on creating the folder following a successful log in. As mentioned, I tried to test this by a button that created the folder. Once everything loaded, and I could see the label with the ID number in it, I tried creating the folder by clicking the button. It created, but it wasn't the ID number, it was the lblID, the default text of the label.

I'm trying to put my finger on this problem. I thought it was an issue with the order everything was loading, but using the button to create the folder to test it still didn't work.

The X is just the name of the module. It's simple. It doesn't signify anything. I keep a lot of code in there, such as:

Public myFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) & "\DailyLog\" '  Main Directory in Program Files"
    Public myAppDataFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "\DailyLog\" '  Main Directory in App Data

    ' ------------- CRITICAL Folder FILES
    Public myCriticalFolder As String = myAppDataFolder & "Critical\"
    Public myBackupFile As String = myCriticalFolder & "Backup File.txt" '  File to save as Backup.
    Public myDetailsFile As String = myCriticalFolder & "Details.txt" '  Details file- area, department, officer, etc.
    Public myLocationsAndCallTypesFile As String = myCriticalFolder & "Locations and Call Types.txt" ' -- File to load Locations / Call Types.
    'Public mySettingsFile As String = myCriticalFolder & "System Settings.ini" '  Settings file for Forms.  Size/Location/etc..
    Public mySettingsAndDataFile As String = myCriticalFolder & "Global Data and Settings.ini" '  Data and Settings for frmOptions.
    Public myShiftStatsFile As String = myCriticalFolder & "ShiftShats.txt" '  Shift Stats for the combo boxes.

    ' -------------- BACKUP log files folder
    Public myBackupLogsFolder As String = myAppDataFolder & "HTMLlogs\"

    ' ------------- FILES Folder FILES
    Public myFilesFolder As String = myAppDataFolder & "Files\"
    Public myOfficerIDFolder As String = myFilesFolder & "" & frmMain.lblID.Text & ""

So I could call x.MyBackupLogsFolder, or x.MySettingsFile. Here's a screenshot showing it to help explain.

ok dear just post the code of form load event....

It looks to me like your problem is

Public myOfficerIDFolder As String = myFilesFolder & "" & frmMain.lblID.Text & ""

You are declaring and initializing the string that contains the folder name at the class level which means that it has its value set before the form even loads (uses the default value of lblID.Text). You can declare the string at the class level, but don't assign it a value until just before you actually create the folder as in

If login is successful then    'pseudo code
    myOfficerIDFolder = myFilesFolder & "" & frmMain.lblID.Text & ""
    x.CreateIDfolder()
End If
commented: Thanks for your time! +3

kingsonprisonic, Reverend Jim and everyone else-

Thank you. You all jogged my thought process enough to get it to work. Here's what I did.

On Form Load, it calls x.CreateIDfolder()

In my x.module, I have this peice of code.

Public Sub CreateIDfolder()
        ' Create the officers folder based on his ID number
        If Not Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "\DailyLog\Files\" & "" & frmMain.lblID.Text & "") Then
            Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "\DailyLog\Files\" & "" & frmMain.lblID.Text & "")
        End If
        ' Move current files into the new folder- the log files based on year.
    End Sub

This sucessfully created the folder, basedon the login ID number, and puts it in the right folder.

I think I might have been getting overly complicated in my earlier approach.

Thank you for all you help, time and patience.

Rob

how does someone log in? are you displaying a login form and if so when? if it is in the form load event before you call CreateIdFolder ensure that it is displayed as modal otherwise the form load event will continue processing and not wait for the user to log in.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.