can this code be improved
can this code be improved
(OP)
hi,
i have a dialog box which contains "make of model" and an input box for "color". if the input box is blank, then the default color will be RED.
i need to input each "make" and "color" into the data-base.
this code seems awkward.can this code be improved? what if i needed to add a 3rd input-box, such as "shape"? i can add the input-box but how do i add that to the code?
thanks
zach
i have a dialog box which contains "make of model" and an input box for "color". if the input box is blank, then the default color will be RED.
i need to input each "make" and "color" into the data-base.
this code seems awkward.can this code be improved? what if i needed to add a 3rd input-box, such as "shape"? i can add the input-box but how do i add that to the code?
CODE
Sub Main()
Dim list(1000) as String
Dim list1(1000) as String
Begin Dialog dlgModelType 0, 1, 330, 300, "Default Color"
ButtonGroup .ButtonPressed
OkButton 250, 20, 50, 14
Text 74, 80, 40, 20, "MAKE"
Text 74, 88, 40, 20, "====="
Text 118, 80, 40, 20, "COLOUR"
Text 118, 88, 40, 20, "========"
Text 76, 100, 30, 20, "AAA:"
Text 76, 114, 30, 20, "BBB:"
Text 76, 128, 30, 20, "CCC:"
Text 74, 142, 30, 20, "DDD:"
Text 76, 154, 30, 20, "EEE:"
Text 78, 170, 30, 20, "FFF:"
Text 74, 184, 30, 20, "GGG:"
Text 74, 198, 30, 20, "HHH:"
Text 84, 212, 30, 20, "III:"
Text 80, 226, 30, 20, "JJJ:"
TextBox 116, 96, 38, 12, .tbx0
TextBox 116, 110, 38, 12, .tbx1
TextBox 116, 124, 38, 12, .tbx2
TextBox 116, 138, 38, 12, .tbx3
TextBox 116, 152, 38, 12, .tbx4
TextBox 116, 166, 38, 12, .tbx5
TextBox 116, 180, 38, 12, .tbx6
TextBox 116, 194, 38, 12, .tbx7
TextBox 116, 208, 38, 12, .tbx8
TextBox 116, 222, 38, 12, .tbx9
End Dialog
'------------------------------------------------------------------
Dim dMain1 as dlgModelType
nRet = Dialog(dMain1)
Typ00 = dMain1.tbx0
Typ01 = dMain1.tbx1
Typ02 = dMain1.tbx2
Typ03 = dMain1.tbx3
Typ04 = dMain1.tbx4
Typ05 = dMain1.tbx5
Typ06 = dMain1.tbx6
Typ07 = dMain1.tbx7
Typ08 = dMain1.tbx8
Typ09 = dMain1.tbx9
List(1) = Typ00
List(2) = Typ01
List(3) = Typ02
List(4) = Typ03
List(5) = Typ04
List(6) = Typ05
List(7) = Typ06
List(8) = Typ07
List(9) = Typ08
List(10) = Typ09
'---------------
List1(1) = "AAA"
List1(2) = "BBB"
List1(3) = "CCC"
List1(4) = "CCC"
List1(5) = "EEE"
List1(6) = "FFF"
List1(7) = "GGG"
List1(8) = "HHH"
List1(9) = "III"
List1(10) = "JJJ"
rw = 1
for i = 1 to 10
mymake = List1 (i)
for j = rw to 10
mycolor = List(j)
if trim(mycolor) = "" then mycolor = "RED"
msgbox mymake + " - " + mycolor
'DO STUFF
'------------------------
'------------------------
rw = rw + 1
exit for
next j
next i
'------------------------------------------------------------------
End Sub
Dim list(1000) as String
Dim list1(1000) as String
Begin Dialog dlgModelType 0, 1, 330, 300, "Default Color"
ButtonGroup .ButtonPressed
OkButton 250, 20, 50, 14
Text 74, 80, 40, 20, "MAKE"
Text 74, 88, 40, 20, "====="
Text 118, 80, 40, 20, "COLOUR"
Text 118, 88, 40, 20, "========"
Text 76, 100, 30, 20, "AAA:"
Text 76, 114, 30, 20, "BBB:"
Text 76, 128, 30, 20, "CCC:"
Text 74, 142, 30, 20, "DDD:"
Text 76, 154, 30, 20, "EEE:"
Text 78, 170, 30, 20, "FFF:"
Text 74, 184, 30, 20, "GGG:"
Text 74, 198, 30, 20, "HHH:"
Text 84, 212, 30, 20, "III:"
Text 80, 226, 30, 20, "JJJ:"
TextBox 116, 96, 38, 12, .tbx0
TextBox 116, 110, 38, 12, .tbx1
TextBox 116, 124, 38, 12, .tbx2
TextBox 116, 138, 38, 12, .tbx3
TextBox 116, 152, 38, 12, .tbx4
TextBox 116, 166, 38, 12, .tbx5
TextBox 116, 180, 38, 12, .tbx6
TextBox 116, 194, 38, 12, .tbx7
TextBox 116, 208, 38, 12, .tbx8
TextBox 116, 222, 38, 12, .tbx9
End Dialog
'------------------------------------------------------------------
Dim dMain1 as dlgModelType
nRet = Dialog(dMain1)
Typ00 = dMain1.tbx0
Typ01 = dMain1.tbx1
Typ02 = dMain1.tbx2
Typ03 = dMain1.tbx3
Typ04 = dMain1.tbx4
Typ05 = dMain1.tbx5
Typ06 = dMain1.tbx6
Typ07 = dMain1.tbx7
Typ08 = dMain1.tbx8
Typ09 = dMain1.tbx9
List(1) = Typ00
List(2) = Typ01
List(3) = Typ02
List(4) = Typ03
List(5) = Typ04
List(6) = Typ05
List(7) = Typ06
List(8) = Typ07
List(9) = Typ08
List(10) = Typ09
'---------------
List1(1) = "AAA"
List1(2) = "BBB"
List1(3) = "CCC"
List1(4) = "CCC"
List1(5) = "EEE"
List1(6) = "FFF"
List1(7) = "GGG"
List1(8) = "HHH"
List1(9) = "III"
List1(10) = "JJJ"
rw = 1
for i = 1 to 10
mymake = List1 (i)
for j = rw to 10
mycolor = List(j)
if trim(mycolor) = "" then mycolor = "RED"
msgbox mymake + " - " + mycolor
'DO STUFF
'------------------------
'------------------------
rw = rw + 1
exit for
next j
next i
'------------------------------------------------------------------
End Sub
thanks
zach
RE: can this code be improved
Hi,
I'd put all the array values and variable control properties in a table somewhere. Excel is handy, cuz, I do almost all my Extra coding in Excel VBA.
Skip,
Just traded in my old subtlety...
for a NUANCE!
RE: can this code be improved
Here's an example of using a table for reading/mapping date from a screen
ScrNam FIELD FR TR CL LN TYP
SF172431 ScrName 1 1 3 8 CHAR
SF172431 ScrDesc 1 1 11 53 CHAR
SF172431 SysDte 1 1 64 8 CHAR
SF172431 SysTme 1 1 73 8 CHAR
SF172431 TRAVELER 3 3 11 7 CHAR
SF172431 BEG OPER 3 3 29 4 CHAR
SF172431 OPER 7 21 2 4 CHAR
SF172431 C/C 7 21 7 3 CHAR
SF172431 MACH GROUP 7 21 11 5 CHAR
SF172431 RUN HRS 7 21 18 7 NUM
SF172431 S/U HRS 7 21 26 5 NUM
SF172431 SPAN DAYS 7 21 32 5 NUM
SF172431 SR CD 7 21 38 1 CHAR
SF172431 PK 7 21 41 1 CHAR
SF172431 FLOW DAYS 7 21 44 4 NUM
SF172431 NOTES 7 21 50 21 CHAR
SF172431 MSG 22 22 2 79 CHAR
I grab the text of the entire screen (1,1,24,80) and process in a loop with various functions.
I have functions to return...
Function GetField(sIn As String, sField As String, Optional nRow As Integer = 0)
Function LoadArray(sScr As String)
Function MultiRow(sField As String) As Boolean
Function NbrRows() As Integer
Function OutCol(sSheet As String, sField As String) As Integer
Function RowHasData(sIn As String, sField As String, r As Integer) As Boolean
Function ScreenSpecRange(sScrn As String, sField As String) As Range
BTW, for setting up a procedure to READ a new screen, takes adding the data to the table, inserting a sheet in my workbook and pasting in the column headings... usually about 10 minutes.
Skip,
Just traded in my old subtlety...
for a NUANCE!
RE: can this code be improved
thanks for the input. yeah, scraping the data is the way to go. i may just consider evoking the script from excel instead...
i just neet to convince the end-user to call up excel
zach
RE: can this code be improved
CODE
Dim Make(3) as String
Dim Color(3) as String
Make(0) = "Car"
Make(1) = "Truck"
Make(2) = "SUV"
Color(0) = "Red"
Color(1) = "White"
Color(2) = "Blue"
Begin Dialog dlgOptions 285, 19, 184, 90, "Selection Dialog Box"
OkButton 130, 6, 50, 14, .btnOK
CancelButton 130, 23, 50, 14, .btnCancel
Text 5, 5, 70, 10, "Make"
DropComboBox 5, 15, 73, 40, Make(), .MakeComboBox
Text 5, 40, 70, 10, "Color"
DropComboBox 5, 50, 73, 40, Color(), .ColorComboBox
End Dialog
Dim dlgVar as dlgOptions
Dialog dlgVar
msgbox "Make = " & dlgVar.MakeComboBox & " Color = " & dlgVar.ColorComboBox
End Sub
Sometimes you gotta leave your zone of safety. You have to manufacture Inspirado. You gotta get out of the apartment. You've got to run with the wolves. You've got to dive into the ocean and fight with the sharks. Or just treat yourself to a delicious hot fudge sundae........ with nuts. - Jack Black
RE: can this code be improved
Sometimes you gotta leave your zone of safety. You have to manufacture Inspirado. You gotta get out of the apartment. You've got to run with the wolves. You've got to dive into the ocean and fight with the sharks. Or just treat yourself to a delicious hot fudge sundae........ with nuts. - Jack Black
RE: can this code be improved
thanks for the input. it will be easier to write this in excel.
zach
RE: can this code be improved
Whenever possible!!!
Skip,
Just traded in my old subtlety...
for a NUANCE!