Display the filename in a text field

This function will update a text field with a file name selected from within a custom menu.

Snippet: 
Function DisplayIt(ControlID$, Action%, SuppValue%)

	If MyFileName = "" Then
		DlgText "txtFilename", "No file selected"
	Else
		DlgText "txtFilename", "File: " & getFileName(MyFileName, 1)
	End If

End Function

Comments

Hi Brian, I created a 'dateSelect' dialog which has a series of drop list boxes to return a start and end date for the testing period back to a 'mainMenu' dialog (which is where I would want the Display it attached to the txtDateRange. The results are passed back to the Main Menu dialog (which will pass the variables forward for testing as needed.)  The variables to hold the start and end date are not global, so I was curious how do I incorporate a local variable with the DisplayIt function? I was able to get the DisplayIt to work if I just made the variables global but trying to avoid it.Any thoughts?  Regards, Mark

Images: 
Brian Element's picture

Hi Mark,

That is an interesting question.  I alwasy use global variables to store items from the dialog so I had to think about this for a bit. 

For the DisplayIt function you need global variables as the function already returns the value of the button selected, this is a special function that you can't return what you want.  So if you are obtaining your variables from within the DisplayIt then they would have to be set as global.

What you can do is obtain the values from the dialog after the dialog call, so you are capturing this information after you have called the dialog. 

I did an example here where I used an array to store the variables.

Option Explicit
 
Sub Main
 Dim sVariables(4) As String
 Dim i As Integer
 Call menu(sVariables())
 
 For i = 0 To 4
  MsgBox sVariables(i)
 Next i
End Sub

Function menu(ByRef sVar() As String)
 Dim dlg As NewDialog
 Dim button As Integer
 
 button = Dialog(dlg)
 
 sVar(0) = dlg.TextBox1
 sVar(1) = dlg.TextBox2
 sVar(2) = dlg.TextBox3
 sVar(3) = dlg.CheckBox1
 sVar(4) = dlg.OptionButtonGroup1
End Function

In this example I am not using the DisplayIt as it is not needed but I could still use it to validate the variables before closing the dialog but still capturing the information in the array.

I have attached an example script for you to have a look at.

Brian

Brian, Thanks for looking into it!  The idea makes sense, I'll just have to try incorporating it which will take me a few minutes to mull over. Dialog boxes are not my strong suit, but mostly because I have not been using them much until recently.  Appreciate your help!  Regards, Mark

Brian Element's picture

No problem, good luck with your project.