Skip to main content

Listbox

I know how to get fieldnames in a list, but is there a way to get the content of a field in a listbox? (Such as debtor names or general ledger ID's)
 
Update:
I got to the point to summarize the selected field (general ledger ID) and export only the content of that field to a txt file and then import it.
 
Open WorkingDirectory & "\Temp.DEL" For Input As File1
Line Input #File1, Contents
MsgBox "The file contains: " & Contents
 
With this code i got the first line in a string, i can't figure out to get the rest in a string at the moment.
 

Brian Element Fri, 08/31/2018 - 09:41

Hi Robert,

I don't use the IDEAScript file functions anymore, there is an object available within windows that is really robust and does a lot more than the function in IDEA.  It is called Scripting.FileSystemObject, if you do a google search on it you will find lots of info.

Here is your script using this object, the script first checks to make sure that the file exits and if it does then it reads all of it and puts the text in a string variable.  There is also a function to read the text line by line.


Sub Main
	Const fsoForReading = 1
	Dim objFSO
	Dim objTextStream
	Dim text As String
	Dim file As String
	strFileName = WorkingDirectory & "\Temp.DEL"
	Set objFSO = CreateObject("Scripting.FileSystemObject")
		If objFSO.FileExists(strFileName) Then
			Set objTextStream = objFSO.OpenTextFile(strFileName, fsoForReading)
				text = objTextStream.ReadAll
				MsgBox text
			Set objTextStream = Nothing
		Else
			MsgBox "The file does not exist"
		End If
	Set objFSO = Nothing
End Sub

Robert van den… Mon, 09/03/2018 - 10:53

okay i understand it, and in my script i create a temp file that is later deleted in the script. But is it possible to go from a string to an array?

Robert van den… Tue, 09/04/2018 - 10:02

In reply to by Brian Element

I think i got it to convert the text file to an array (line 150 to 152). But when i use the for each function to display the array content in a message every time i run it, i get subscript out of range on line 161. So i'am doining something wrong. I have looked at the Append File Report script, but I can not really isolate where what happens in the script.

Brian Element Tue, 09/04/2018 - 10:37

In reply to by Robert van den…

You can't use the ReadAll function in this case as you want to read it in line by line, that is why you are putting it in an array.  If you want to use the readall then you create a string variable to hold the entire text (so long as it is less than 64,000 characters, that is around the limit of a string variable).

Also you have defined your array but you haven't actually initialized it, so far you have an array of nothing and you haven't said it should hold anything that is why you are getting the error.

So you need to create a new boolean variable called bFirstTime and set it as true:

Dim bFirstTime as Boolean

bFirstTime = True

Replace your for next loop with a Do Until loop as you don't know how many items will be in the file.  The For Next loop is usually used when you know how many items to start off with.


Do Until objTextStream.AtEndOfStream 'must use a loop as there is no way to know how many items in the text file
	If bFirstTime Then 'if this is the first item then redefine the array for 1 item
		bFirstTime = False 'change this so this is only run once
		ReDim text(0) 'initialize the array to 1 item
		text(0) = objTextStream.ReadLine 'place the first item into the array
	Else
		ReDim preserve text(UBound(text) + 1) 'increase the array by 1 element
		text(UBound(text)) = objTextStream.ReadLine 'place the next line at the end of the array
	End If
Loop

Robert van den… Fri, 09/07/2018 - 04:42

In reply to by Brian Element

I got it working, the one thing i changed to show the selected value in a messagebox is that when the script place the item in an array it is not in text() but in list3$() array. Because for some reason i didn't understand when i connected a string variable to the dialog droplistbox it would show the array number but not the content/text. How is the indentation style in my script?

Brian Element Fri, 09/07/2018 - 10:33

In reply to by Robert van den…

Hi Robert,

It is much easier to read with the indentation. You still need some additional indentation, such as the Select Case ControlID$ should be indented twice more and everything that goes along with it as this is part of Case 2 so it should be indented accordingly.

The listbox returns the number of the item selected with the first item being 0 and so on.  You have to match this up with the original array to obtain the string value of what you are looking for in the listbox.

Brian