Liberty BASIC Community Forum
« Upper Bounds on string array »

Welcome Guest. Please Login or Register.
Nov 24th, 2017, 10:57am


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Upper Bounds on string array  (Read 196 times)
Noble D. Bell
Board Moderator

member is offline

Avatar




PM

Gender: Male
Posts: 932
xx Upper Bounds on string array
« Thread started on: Jul 1st, 2017, 7:52pm »

Been coding all day and brain turning to mush. smiley

Is there an easy way to determine the size of a string array through code?

Ex. I have a string array with a number of elements in that array but I am unsure of the upper bounds. Is there a way to determine that?

or..

Is there an easy way of counting the number of items in a listbox without knowing the size of the array being used?

Thanks in advance.
User IP Logged

Thank you and God bless,
Noble D. Bell
http://www.noblebell.com
Dan Teel
Guru
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1130
xx Re: Upper Bounds on string array
« Reply #1 on: Jul 1st, 2017, 11:03pm »

You could do something like this

Code:
dim strArray$(1000)

on error goto [nope]
testLen=10000
[nope]
testLen=testLen-1
blank$=strArray$(testLen)

print "array length is ";testLen
 


You could make it more efficient by doing halfsies.

Other than that, I cant really say.


For the getting the listbox item count you can use the LB_GETCOUNT message

Code:
    dim array$(123)

    for i = 1 to 123
        array$(i)=str$(rnd(1))
    next i

    nomainwin
    WindowWidth = 550
    WindowHeight = 410
    UpperLeftX=int((DisplayWidth-WindowWidth)/2)
    UpperLeftY=int((DisplayHeight-WindowHeight)/2)


    ListboxColor$ = "white"
    listbox #main.listbox2, array$(), [listbox2DoubleClick],   50,  42, 245, 205
    button #main.button3,"get count",[button3Click], UL, 310,  92, 100,  25

    '-----End GUI objects code

    open "untitled" for window as #main
    print #main, "font ms_sans_serif 10"
    print #main, "trapclose [quit.main]"


    wait



[listbox2DoubleClick]

    wait


[button3Click]
    lbhwnd=hwnd(#main.listbox2)
    calldll #user32,"SendMessageA",_
        lbhwnd as ulong,_
        _LB_GETCOUNT as ulong,_
        0 as long,_
        0 as long,_
        count as long

    notice "Items = ";count
    wait

[quit.main]
    close #main
    end
 
« Last Edit: Jul 1st, 2017, 11:13pm by Dan Teel » User IP Logged

ZPtr.net
Brandon Parker
Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1118
xx Re: Upper Bounds on string array
« Reply #2 on: Jul 2nd, 2017, 09:33am »

Noble,
Feel free to use any of the functions that are located in the links provide in my Dynamic Arrays thread. Let me know if you find what is there useful. I am pretty sure I've updated the library since the last time I posted in that thread. Feel free to let me know if you have any other questions.

Here's how I find the Upper Bound of a string array (also in my Dynamic Arrays library).

Code:
On Error GoTo [ErrorMain]
Dim ArrayName1$(4)
ArrayName1$(0) = "Zero"
ArrayName1$(1) = "One"
ArrayName1$(2) = "Two"
ArrayName1$(3) = "Three"
ArrayName1$(4) = "Four"

Notice "The Upper Bound is Element # (" + str$(UBoundStringArray("ArrayName1")) + ")."

    Function UBoundStringArray(arrayname$)
        On Error GoTo [Error]
            Do Until UBoundStringArray = -1
                temp$ = Eval$(arrayname$ + "$(" + str$(UBoundStringArray) + ")")
                UBoundStringArray = (UBoundStringArray + 1)
            Loop
        [Error]
            UBoundStringArray = (UBoundStringArray - 1)
    End Function

[ErrorMain]
     Notice "It never raises this error block."

End 



{:0)

Brandon Parker
« Last Edit: Jul 2nd, 2017, 09:33am by Brandon Parker » User IP Logged

Windows 7 Home Premium 64-bit Intel(R) Quad Core(TM) i5 CPU M 430 @ 2.27GHz 4GB DDR3 RAM
Noble D. Bell
Board Moderator

member is offline

Avatar




PM

Gender: Male
Posts: 932
xx Re: Upper Bounds on string array
« Reply #3 on: Jul 2nd, 2017, 5:03pm »

Thank you guys. That did the trick and helped my old tired brain out.

User IP Logged

Thank you and God bless,
Noble D. Bell
http://www.noblebell.com
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls