Jump to content

Need help with parameters


Dawn99
 Share

Recommended Posts

Hi- my current code will pull one line of engraving from the database but I need it to pull up to 2 lines. I tried changing it and got it to pull 2 lines IF there was 2 lines:

$eng2 = $engResult[2][0]
    $pieceEng &= $tag & ":font " & $font &" Line1: " & $eng & " :Line2: " & $eng2

but it was crashing if there was only one. How do I change it so it will pull as many lines as there are available? Here is what I have that pulls one line:

Func _Corel_lookup_engraving(ByRef $pieceEng, Const $pieceID, Const $tag)
    $engQuery = "SELECT engraving,Font FROM thm_layout_eng WHERE PieceID = " & $pieceID
    $engResult = _AQuery($dbConnection, $engQuery)
    If UBound($engResult)=1 Then
        Return(0)
    EndIf

    $eng = $engResult[1][0]
    $font = $engResult[1][1]
    
    ;Add a line break if previous engraving
    If StringLen($pieceEng) <> 0 Then
        $pieceEng &= @CRLF
    EndIf

    $pieceEng &= $tag & ":font " & $font &" Line1: " & $eng

    Return(0)
EndFunc

Link to comment
Share on other sites

Hi Dawn, and welcome!

You can check the length of the array returned using UBound...

; If the array has more than one row... see below
If UBound($engResult, 1) > 1 Then
    $eng2 = $engResult[2][0]
    $pieceEng &= $tag & ":font " & $font &" Line1: " & $eng & " :Line2: " & $eng2
EndIf

; Your array will look like this:
; [
;   ["line 1 cell 1", "line 1 cell 2"],
;   ["line 2 cell 1", "line 2 cell 2"]...
;]

And next time, it's helpful to put code in using our handy dandy code input tool... you'll see it looks like this <> when you're creating a post :) 

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

Thanks SeaDoggie- I changed it so it now reads:

Func _Corel_lookup_engraving(ByRef $pieceEng, Const $pieceID, Const $tag)
    ;Lookup engraving for this piece
    $engQuery = "SELECT engraving, Font FROM thm_layout_eng WHERE PieceID = " & $pieceID
    $engResult = _AQuery($dbConnection, $engQuery)
    If UBound($engResult)=1 Then
        Return(0)
    EndIf

    $eng = $engResult[1][0]
    $font = $engResult[1][1]
    
    ;Add a line break if previous engraving
    If StringLen($pieceEng) <> 0 Then
        $pieceEng &= @CRLF
    EndIf

    $pieceEng &= $tag & ": " & $eng

    If UBound($engResult, 1) > 1 Then
    $eng2 = $engResult[2][0]
    $pieceEng &= $tag & ":font " & $font &" Line1: " & $eng & " :Line2: " & $eng
    EndIf

Return(0)
EndFunc

But it crashed on the line that starts $eng2 with the error: "Array  variable has incorrect number of subscripts or subscript dimension range exceeded"

Link to comment
Share on other sites

Ooops, sorry, change the Ubound line to this: If UBound($engResult, 1) > 2 Then

I can't test the code and didn't look close enough, sorry :)

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

Thank you so muchSeadoggie!!!

I can not tell you how much time you saved me. I did have to change it a bit because it was duplicating line one so here is my final:

Func _Corel_lookup_engraving(ByRef $pieceEng, Const $pieceID, Const $tag)
    ;Lookup engraving for this piece
    $engQuery = "SELECT engraving, Font FROM thm_layout_eng WHERE PieceID = " & $pieceID
    $engResult = _AQuery($dbConnection, $engQuery)
    If UBound($engResult)=1 Then
        Return(0)
    EndIf

    $eng = $engResult[1][0]
    $font = $engResult[1][1]
    
    ;Add a line break if previous engraving
    If StringLen($pieceEng) <> 0 Then
        $pieceEng &= @CRLF
    EndIf

    $pieceEng &= $tag & ":font " & $font & ": " & $eng

    If UBound($engResult, 1) > 2 Then
    $eng2 = $engResult[2][0]
    $pieceEng &= $tag & " :Line2: " & $eng2
    EndIf

Return(0)
EndFunc

You are a life saver!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...