Jump to content

Welcome to eMastercam

Register now to participate in the forums, access the download area, buy Mastercam training materials, post processors and more. This message will be removed once you have signed in.

Use your display name or email address to sign in:

How to use VBS Array function to arrange the number


pohyg
 Share

Recommended Posts

Hello,

 

Can anyone help,

below was the Script i want to make it the result output from smaller number to big number (5,6,10,15 .), can advise me how to arrange ( short out) the below array numbers .

 

Note : My result was (10 , 15, 5, 6)

do not adjust p = Array(w,x,y,z)

 

Call Main()

Sub Main()

 

Dim s(3)

Dim w

Dim x

Dim y

Dim z

Dim p

 

w = 10

x = 15

y = 5

z = 6

 

p = Array(w,x,y,z)

 

Dim a

 

For a = 0 To 3

 

s(a) = p(a)

ShowString s(a)

 

 

 

Next

 

 

End Sub

 

Thank you .

 

Best Regards,

 

Poh Yew Guan

 

TECHTOWN Pte Ltd

 

Distributor for Mastercam® & IMOLD

 

in Singapore, Indonesia, Thailand, Middle East,

 

Vietnam and China

Link to comment
Share on other sites

code:

Call Main

 

Sub Main()

 

Dim varData(3)

Dim varNew

Dim intI

 

 

varData(0)= 22

varData(1)= 11

varData(2)= 61

varData(3)= 19

 

For intI = LBound(varData) To UBound(varData)

 

MsgBox varData(intI)

 

Next

 

varNew = GetSortedArray(varData)

 

For intI = LBound(varNew) To UBound(varNew)

 

MsgBox varNew(intI)

 

Next

 

End Sub

 

Function GetSortedArray(varArray)

 

Dim intCount

Dim intNumber

Dim varTempData

 

For intCount = UBound(varArray) - 1 To 0 Step -1

 

For intNumber = 0 To intCount

 

If varArray(intNumber) > varArray(intNumber+1) Then

 

varTempData = varArray(intNumber+1)

varArray(intNumber+1) = varArray(intNumber)

varArray(intNumber) = varTempData

 

End if

 

 

Next

 

Next

 

GetSortedArray = varArray

 

 

End Function

Link to comment
Share on other sites

Hello ,

 

Pip and Saipem Thank for your help .

 

Saipem your program was work , i will apply

 

this to toollist for the Excel format

 

but how about sort the string from A to Z.

 

I was the beginner to try writting some VB

 

programs , anyway thanks and hope next time you

 

can assist .

 

Best Regards,

 

Poh Yew Guan

 

TECHTOWN Pte Ltd

 

Distributor for Mastercam® & IMOLD

 

in Singapore, Indonesia, Thailand, Middle East,

 

Vietnam and China

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

Join us!

eMastercam - your online source for all things Mastercam.

Together, we are the strongest Mastercam community on the web with over 56,000 members, and our online store offers a wide selection of training materials for all applications and skill levels.

Follow us

×
×
  • Create New...