• This forum is the machine-generated translation of www.cad3d.it/forum1 - the Italian design community. Several terms are not translated correctly.

string order both with vba and vlisp

  • Thread starter Thread starter ghirosoft
  • Start date Start date

ghirosoft

Guest
Bye to all,

I have to recover the list of layers of an electrical schematic consisting of layer type 1,2,3,5,10,12a,13,15,16a etc.
Actually this list recovers in vba but I'm trying with vlisp.
with vba matching the list to a listbox shows me 1,10,12a,13,15,16a,2,3,5.
I am trying precisely with vlips but not being whole number because there are letters after the number, I hold them as strings and order the list with vl-sort, but it does not give me the correct progression. I'm pretty much back on the second list.
with vba I have a function to order numbers but not with letters. I also tried to download something I found around but nothing. Do I have to try with a listview that I know that it has the order directly on the property of the object?

in vba would like to change a bit of code.
or am I losing on a glass of water? ?

Thank you.
 
txt="000" & layer
if right(layer,1)
order according to the new carrier and use its index to order the base one.

see if it works, if it is not clear, let me know that I place an example.

bye
 
Bye to all,

I have to recover the list of layers of an electrical schematic consisting of layer type 1,2,3,5,10,12a,13,15,16a etc.
Actually this list recovers in vba but I'm trying with vlisp.
with vba matching the list to a listbox shows me 1,10,12a,13,15,16a,2,3,5.
I am trying precisely with vlips but not being whole number because there are letters after the number, I hold them as strings and order the list with vl-sort, but it does not give me the correct progression. I'm pretty much back on the second list.
with vba I have a function to order numbers but not with letters. I also tried to download something I found around but nothing. Do I have to try with a listview that I know that it has the order directly on the property of the object?

in vba would like to change a bit of code.
or am I losing on a glass of water? ?

Thank you.
with vba you can proceed with strcomp

below an example of boubleshort to order precisely numbers in string format with letters inside.

in the example below "last" is the end of the array, in excel the thing works correctly. Try to see.
Code:
    for i = 1 to ultima - 1
        for j = 1 to ultima - 1
        a = activesheet.range("a" & j).value
        b = activesheet.range("a" & j + 1).value
        confronto = strcomp(a, b)
            if confronto > 0 then
                temp = activesheet.range("a" & j).value
                activesheet.range("a" & j).value = b
                activesheet.range("a" & j + 1).value = temp
            end if
        next j
    next i
 
Damn, guys! !
Thank you.
I tried reordering in lisp and it works, as soon as I can and hope soon I will try what you posted in vba.
Thank you again.
 
hi shape,
I tried like that.
If I do so
Last = 10
pippo = array("", "1", "2", "1a", "5", "3", "10", "12a", "12", "11", "15")

for i = 1 to last - 1
for j = 1 to last - 1
a = pip(j)
b = pip(j + 1)
comparison = strcomp(a, b)
if comparison > 0 then
temp = pippo(j)
pippo(j) = b
pippo(j + 1) = temp
end if

next i
He answers:

"1" "10" "11" "12a" "15" "1a" "2" "3" "5"
while I take off the array "" (then index 0)

at some point tells me that out of range in b = pippo(j + 1)... rightly.
I've done a lot of evidence between the number of Array and the last.
I saw however that strcomp is the only one to verify alphanumeric data.

x rpor66.. .
I think I understand your example even if I don't try. If by chance you have the example under hand and the places would go more on the safe.

Thank you!
 
Code:
public sub ordina()

dim pippo as variant
dim pippo1 as variant

dim i as integer
dim index as string

pippo = array("10", "12", "14a", "14", "6", "13", "1", "3", "2", "4", "5")
pippo1=pippo

for i = lbound(pipe) to ubound(pipe)
for j = lbound(pipe) to ubound(pipe) - 1


if len(pippo(j)) = 1 then index = " 'according to the type of string 2 for xxx
if len(pippo(j)) = 2 then index = " 'according to the type of string 1 for xx

a = index & pippo(j)

if len(pippo(j + 1)) = 1 then index = " 'according to string type 2 for xxx
if len(pippo(j + 1)) = 2 then index = " based on the type of string 1 for xx

b = index & pip(j + 1)

comparison = strcomp(a, b)
if comparison > 0 then
temp = pippo(j)
pippo(j) = pippo(j + 1)
pippo(j + 1) = temp
end if
♪
next i

pisgbox (pippo1(0) & pippo1(1) & "-" & pippo1(2) & "-" & pippo1(3) & "-" & pippo1(4) & "-" & pippo1(5) & "-" & pippo1(6)" & pippo1(7) & pippo1(7) & pippo-

end
ok now it works, I had tried with values that had the same length, just use the make-up index put 1 or two spaces according to the length. so the comparison is made at equal length string.

It would only be enough to make a prior reading of the array to determine the max length and according to that put the spaces in reading.
 
thanks to the availability.
But if the array becomes like this:

public sub ordina()

dim pippo as variant
dim pippo1 as variant

dim i as integer
dim index as string

"pippo = array("10", "12", "14a", "14", "6", "13", "1", "3", "2", "4", "5")
pippo = array("10", "12", "14a", "14", "6", "13", "1", "3", "2", "4", "5", "2a")

pippo1 = pippo

for i = lbound(pipe) to ubound(pipe)
for j = lbound(pipe) to ubound(pipe) - 1


if len(pippo(j)) = 1 then index = " 'according to the type of string 2 for xxx
if len(pippo(j)) = 2 then index = " 'according to the type of string 1 for xx

a = index & pippo(j)

if len(pippo(j + 1)) = 1 then index = " 'according to string type 2 for xxx
if len(pippo(j + 1)) = 2 then index = " based on the type of string 1 for xx

b = index & pip(j + 1)

comparison = strcomp(a, b)
if comparison > 0 then
temp = pippo(j)
pippo(j) = pippo(j + 1)
pippo(j + 1) = temp
end if

next i

pisgbox (pippo1(0) & pippo1(1) & "-" & pippo1(2) & "-" & pippo1(3) & "-" & pippo1(4) & "-" & pippo1(5) & "-" & pippo1(6)" & pippo1(7) & "

end

verify yourself the result.
 
Code:
public sub ordina()

dim pippo as variant
dim pippo1 as variant
dim a, b as string
dim temp as string
dim i, x, j, y as integer

pippo = array("2a", "10", "12", "14a", "14a", "13", "1", "3", "2", "4", "5", "6")
pippo1 = pippo

for i = lbound(pipe) to ubound(pipe)
for j = lbound(pipe) to ubound(pipe) - 1

a = pip(j)
b = pip(j + 1)

if asc(right(a, 1)) > 65 then a = mid(a, 1, len(a) - 1)
if asc(right(b, 1)) > 65 then b = mid(b, 1, len(b) - 1)


if val(a) > val(b) then
temp = pippo(j)
pippo(j) = pippo(j + 1)
pippo(j + 1) = temp
end if
♪
next i

pisgbox (pippo1(0) & pippo1(1) & "-" & pippo1(2) & "-" & pippo1(3) & "-" & pippo1(4) & "-" & pippo1(5) & "-" & pippo1(6)" & pippo1(7) & "

end
Okay, so orders, but you don't have control if number 2 is before 2a if this is not such a problem solve.

I didn't have much time to "play" so maybe there is a more appropriate method !!!
 
I tried and actually does not put in order 2 with 2a,
However, returning to the function that uses "strcomp" if you do these tests gives you correctly 1 or -1 depending on the comparison.

pippo = strcomp("002", "02a", vbtextcompare)
pippo = strcomp("02b", "02a", vbtextcompare)
pippo = strcomp("002", "02a", vbtextcompare)

Now I wonder, why do we find ourselves in the function for example the 2nd at the end? ?
I'm not asking you.

mal going from vba launch the vlips function that orders correctly and then recover the array variable.

Thank you again.
 
Sorry I'm late.... .
the attached file and a excel sheet, I do not have vba for autocad but it is equal.
by opening the sheet in the column to the values to be ordered, press the reorder button, and in column b the ordered values will be copied.

in the form you find 2 subs, the one that interests you is ordering, the call by passing the carrier to order and the routine orders you the carrier itself.

bye
 

Attachments

the delay???? Yes!
I tried so:

private sub commandbutton4_click()

vector = array("1", "1b", "1a", "3", "5", "10a", "10", "11", "20b", "20a", "22", "2")


dim a as string
dim i as integer
dim j as integer
dim min as integer
dim max as integer
dim txt1 as string
dim txt2 as string

min = lbound(vector)
max = ubound(vector)
for i = min to max
for j = i to min + 1 step -1
txt1 = right("0000" & vector(j - 1), 5)
txt2 = right("0000" & vector(j), 5)
if right(txt1, 1) < "a" then txt1 = right(txt1 & "0", 5)
if right(txt2, 1) < "a" then txt2 = right(txt2 & "0", 5)
if txt1
a = carrier(j - 1)
carrier(j - 1) = carrier(j)
carrier(j) = a
end if

next i

end


It's fun. ! ! ! !
I think there's no problem when I put it in my routine.
It's an endorsement for layered electric schematics, but it also serves us, as a firm, this update.
when I have placed the public on my site and write the link here in the forum.
I think there will be more than someone interested in this order:smile:
Thank you very much!! !
 
Sorry I'm late.... .
the attached file and a excel sheet, I do not have vba for autocad but it is equal.
by opening the sheet in the column to the values to be ordered, press the reorder button, and in column b the ordered values will be copied.

in the form you find 2 subs, the one that interests you is ordering, the call by passing the carrier to order and the routine orders you the carrier itself.

bye
as always great.. I went close with the boublesort but I missed your prefix kikka... great

I allow myself to add a small control to not have problems on the size of the strings to be ordered, with this you can have what length you want and not only below 5 digits.
Code:
sub ordina(byref vettore() as string)
    
    dim a as string
    dim i as integer
    dim j as integer[COLOR="Red"][B] dim x as integer
dim y as integer
dim maxl as integer
dim maxlen as integer[/B][/COLOR]
    
    dim min as integer
    dim max as integer
    dim txt1 as string
    dim txt2 as string
    dim maxl as integer
    dim maxlen as integer
    
    min = lbound(vettore())
    max = ubound(vettore())
    
    [COLOR="Red"][B]    for x = min to max
        maxl = len(vettore(x))
        if maxl > maxlen then maxlen = maxl
    next x
    
    
    dim prefisso as string
    prefisso = ""
    
    for y = 1 to maxlen
        prefisso = prefisso & "0"
    next y[/B][/COLOR]
    
    for i = min to max
        for j = i to min + 1 step -1
 [COLOR="red"][B]           txt1 = right(prefisso & vettore(j - 1), maxlen)
            txt2 = right(prefisso & vettore(j), maxlen)
            if right(txt1, 1) < "a" then txt1 = right(txt1 & "0", maxlen)
            if right(txt2, 1) < "a" then txt2 = right(txt2 & "0", maxlen)[/B][/COLOR]If txt1 > txt2 then
1)
vetries - 1) = vetritore)
= a
End if
mxt nxt
mxt i
End sub
in red the changes to the original, please rpor66 forget if I wrote a cable.
 
for y = 1 to maxlen prefisso = prefisso &quot; 0 &quot; next and
you can replace it with prefix = string(maxlen,
"0")

to note that in any case this routine serves
order lists formed by optionally followed numbers
by letter, find numbers greater than 4 digits
means lists ranging from 1÷9999.

bye
 
find larger numbers of 4 digits
means lists ranging from 1÷9999.
[/B][/COLOR]
bhè you are right, it is that I tried the rutine for another thing and I noticed the limit of the number of characters, so doing you do not have problems and therefore it is applicable more generically.

Code:
example to order and/or group equal positions in a separate pieces
to be able then to sum and get the totals.
01
01
01
01
01
01
01
01
01b
01b
_
_
_
03a
03a
03a
012a
012a
012a
012b
012b
012b
040a
040a
040a
040b
040b
040b
0400a
0400b
however as usual you are decisive to solve these hangings!
 

Forum statistics

Threads
44,997
Messages
339,767
Members
4
Latest member
ibt

Members online

No members online now.
Back
Top