Try an array.
I am converting some of my Excel VB programs into VB Express. I generally have a lot of inputs, and generate GCode from those inputs
Is there any way in VB Express to get that information without using textbox1, textbox2, etc? (like textbox(n), and using a loop to index in each time)
The reason I want to do this -- and maybe there is a better way than a textbox -- is I have a form that has 3 columns for x, y, z values indicating where I want to drill a hole. There could be 1 or up to 100 rows of x,y,z values. I would like to step through one row at a time until there are no more values on the row, then exit the program. I would like to do this without having to type in code for textbox1 to textbox100.
How do you change the textbox name to indicate it is an array?
"maybe there is a better way than a textbox"
Textbox arrays are easy to use, but potentially make for a LOT of code.
I'm not sure I understand your project... You have a form with 3 columns of x,y,and (or) z coordinates. Like this?
X1 Y3 Z-2
And you want to read one line at a time, and do... what?
If you already have the data in some format that can be saved in text format, then it's pretty easy to read the data in one line at a time:
Open "filename.txt" for input as #1
line input #1,a$
*** do stuff ***
If I knew more about what you wanted to do with the data, I could be a little more helpful.
That's close. The form looks like this:
X.........Y...........Z <<< Label for columns
1.5 .......2........3.5 <<< Row 1, three textboxes for input
2.........2.5........4 <<< Row 2
I have several "generic" GCode generators -- each read from an input form and write GCode to an output file for simple operations.
The one above is for a drill pattern. The program reads Row 1, and writes Gcode to send the mill to the Row 1 X,Y position at a safe Z, then moves to the Row 1 Z value and retracts to a safe Z. The program then moves to row 2 and does the same thing. When there is a blank row, the program stops, and closes the GCode file.
What you show above is reading from an external file. I want to read the user input from the VB form (there is no external file at this point).
I'd use one row of text boxes and store the data in an array. Store the data as it's entered. Use a forward and back button to cycle through the array.
Mach3 2010 Screenset
(Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)
Thanks for the inputs.
I would like to see all of the inputs at once, and be able to change any of them. You could do that with a single set of boxes, but I think typing in TextBox1 to TextBox100 will be easier in the long run -- and I probably will not go to 100 to make it easier.
I agree, a lot of text boxes would be a pain.
3 boxes per row (x, y, z) and 100 rows = 300 text boxes
I think you could do this with one multiline text box. You could use a comma delimited data entry method with line feeds. See attached file
The "SPLIT" function in VB could be used to break the text box multiline text into the x, y, and z locations. The "SPLIT" function can also find a new line using the ASCII character 10 and 13 for carriage return and line feed.
Another way of making the manual data entry easier would be to use Microsoft Excel. Use the spreadsheet's columns for the X, Y, and Z data. Of course, the spreadsheet's rows contain the individual Drill file position.
You could then take the Excel spreadsheet and write an excel macro to convert this data into a Gcode CNC file or save it as a Comma Delimited text file. The Comma Delimited text file would need to be converted into Gcode using VB.
Thanks. I actually have an Excel spreadsheet that does exactly that, but was hoping to duplicate it in VB Express.
How about a list box, three text boxes, and three command buttons. The List Box shows all of your manual entry cooridinates in a comma or tab delimited format, Example (0.001 9.0123 5.002). You can scroll through the list and select a row. When you select a row of data the X, Y, Z data appears in the three text boxes for editing. The three command buttons could ADD, UPDATE, or DELETE the current selected row of data in the List Box. The default selected row could always be the last row in the list. Therefore, if you click the ADD button it will always add the data to the end of you List Box. When your done, I suppose you will need a "Generate GCODE" button or menu option.
Does the Express version let you add controls/components? For example, normal VB 6 allows you to add controls/components (with Ctrl-T). There are some "Microsoft Windows Common Controls" in mscomctl.ocx, mscomct2.ocx, etc that you may want to look at. Somewhere there is a grid control if you were longing for the Excel look and feel. A google search may turn up a grid-control that you could download for cheap or free.
Otherwise, I like Megahertz suggestion. I think it would be a good interface and you could always add a right-click "import" and "export" command to deal with text files later on.
Here is some VB6 code which will read a Excel file when the data is in columns : X figure in Column A: Y figure in B: Z figure in C, and paste into a textbox in your VB program.
This may help to get you started with VB Express if this is what you require.
Pics show the data in Excel and the VB text box which can be scrolled.
Private Sub Command1_Click()
Dim xlApp As Excel.Application
Dim xlBook1 As Workbook
Dim xlSheet1 As Worksheet
Set xlApp = Excel.Application
Dim strX As String
Dim strY As String
Dim strZ As String
Dim strLine As String
Dim strACell As String
Dim strBCell As String
Dim strCCell As String
FileName = "C:\TestXYZ2TextBox\Book1.xls"
Set xlBook1 = xlApp.Workbooks.Open(FileName)
xlApp.Application.ScreenUpdating = True
'xlApp.Visible = True
For L = 2 To 10
strLine = L
strX = "": strY = "": strZ = ""
strACell = Chr$(65) + strLine
strX = CStr(ActiveCell.Value)
strBCell = Chr$(66) + strLine
strY = CStr(ActiveCell.Value)
strCCell = Chr$(67) + strLine
strZ = CStr(ActiveCell.Value)
strData = strData & "X" & strX & " Y" & strY & " Z" & strZ & Chr$(13) & Chr$(10)
txtData.Text = strData
Last edited by Kiwi; 01-02-2007 at 06:26 AM.