Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can this code be improved

Status
Not open for further replies.

vzachin

Technical User
Feb 10, 2006
305
0
0
US
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?

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

thanks
zach
 



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,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 


Here's an example of using a table for reading/mapping date from a screen
[tt]
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
[/tt]
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...
[tt]
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
[/tt]
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,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
hi Skip,

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 :-D


zach
 
Code:
Sub Main
    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

[small]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[/small]
 
That may not be remotely close to what your attempting, but it's what I got from the original post. With further explanation I can be of further help. I hope :)

[small]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[/small]
 
hi IknowMe,

thanks for the input. it will be easier to write this in excel.

zach
 


zach said:
it will be easier to write this in excel.
Whenever possible!!!

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top