How do I call for a user defined string from a different function?

I don't have much experience with programming but I have been looking all over the place on how to use a user-defined string variable in another function. I have made the variable global and have tried several methods to call for it and I keep getting the error "While executing a user function, the following error occurred: attempt to use a null string variable." 

The program prompts the user to enter the sample name in the first function as soon as you start the program. I took that string variable and defined it as a new global string.

Function/S AutoAnalysis()
    string sampleName, ADC, Rwave, Cwave, Vwave, Twave, Analysis, Wstats, folderName
    variable sampleThickness, workingDiameter, scalar, n, jumper, i
   
    NewDataFolder/O/S Sample

    LoadInFile()
....
    Prompt sampleName, "Enter sample name"
    DoPrompt "Sample Name", sampleName
    string/G gSampleName = sampleName

I am now making a function to call within a macro for each time I create a new graph, and I want it to take that sampleName and reuse it in the title. When I run this macro I get the error and the title shows up with everything correct, except it doesn't include the sample name. 

Function CreateTitle()
    string voltageStep
    SVAR gSampleName=gSampleName
   
    Prompt voltageStep, "Enter voltage value"
    DoPrompt "Voltage Value", voltageStep
   
    String titleText
    sprintf titleText, "%s Conductivity at %s V (Baked, Log-Log)", gSampleName, voltageStep
    TextBox/A=MT/E/C/N=Title/F=0 titleText
End

When I check the data browser, it shows that "gSampleName" does equal the variable that the user defines, so I don't know why it is saying the variable is "null" when it isn't, so I must be calling it wrong. Anyone know what the problem could be?

 

And is case this might be relevent, LoadInFile() is

Function/S LoadInFile()
    LoadWave/G/W
End

 

Hi,

One thing I would check is to see if gSampleName is in the active directory.  I see a NewDataFolder command in the function where it is defined.

If for some reason the current directory is switched it will not find it.

Andy