OberonPlace.com Forums

OberonPlace.com Forums (http://forum.oberonplace.com/index.php)
-   CorelDRAW/Corel DESIGNER VBA (http://forum.oberonplace.com/forumdisplay.php?f=16)
-   -   vba Left not working (http://forum.oberonplace.com/showthread.php?t=6980)

runflacruiser 19-05-2010 17:20

vba Left not working
 
Hi.

I have a module I am using to build a function. In this I'm using something like this example:
Code:

dim str as string, myOtherString as string
myOtherSring = "test"
str = Left(myOtherString , 1)
msgbox str ' should be "t"

and it doesn't work. I get error:

Compile error:
Wrong number of arguments or invalid property assignment.

I even tried:
Code:

MsgBox Left("test", 1)
in the intermediate window of this module and still no dice.

The funny thing is that it works fine in another module.
I tried sub, private sub and still no.

Here's a similar reference I found
reference1

reference 2

Has anyone had a similar experience with this?
-John

shelbym 19-05-2010 17:40

str
 
str is a built in function, you can't use it. :-)

Also myOtherSring = "test" you forgot the r, Option Explicit will help catch this type of error. :-)

-Shelby

runflacruiser 19-05-2010 19:32

HI Shelby.
Oops, Cause I typed that example in the forum box, not copy and pasted from actual code.

Here's the sub (soon to be function.)
I'm guessing you'll know what it's for.
I want to validate a string beginning with a specified range of letters, and set and ultimately return the boolean.

Just in case you know a shorter, faster way, I'd love to hear it. It works fine, I think. I haven't really tested because the left function not working in this module is bugging me...lol

Str function?

Code:

Option Explicit

Sub test()

End Sub
Sub letterPass()
    'soon to be a function ' ()as boolean
    Dim fontName As String, startLet As String, endLet As String
    Dim abcArr As Variant
    Dim letter As String
    Dim startKey As Long, endKey As Long
    Dim pass As Boolean
    Dim i As Integer, j As Integer, k As Integer
   
   
    pass = False 'flag set
   
    startLet = "@": endLet = "0"
    fontName = "@try"

    letter = Left(fontName, 1) 'not working...hmmmmmm
    'letter = "@" 'for testing
   
    'may move array outside function for more speed. This is for now.
    abcArr = Split("@ # ! ? ( ) * . 0 1 2 3 4 5 6 7 8 9 0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z")

    'get start key
    For i = 0 To UBound(abcArr)
      If abcArr(i) = startLet Then startKey = i
    Next i
   
    'get end key if set. This will be an optional param of the function.
    If endLet <> "" Then
        For j = 0 To UBound(abcArr)
          If abcArr(j) = endLet Then endKey = j
        Next j
    Else
        endKey = startKey
    End If
   
    'check fontname against each first letter value in range
    For k = startKey To endKey
        If UCase(letter) = abcArr(k) Or LCase(letter) = abcArr(k) Then pass = True
    Next k
   
    MsgBox pass 'is the fname inbetween the specified letter range
End Sub

-John

shelbym 19-05-2010 21:47

Str
 
Quote:

Originally Posted by runflacruiser (Post 16518)
Str function?

Str Function

Returns a Variant (String) representation of a number.

Dim MyString
MyString = Str(459) ' Returns " 459".
MyString = Str(-459.65) ' Returns "-459.65".
MyString = Str(459.001) ' Returns " 459.001".

-Shelby

runflacruiser 19-05-2010 21:54

Quote:

Originally Posted by shelbym (Post 16517)
str is a built in function, you can't use it. :-)

-Shelby

Hi.
I know. I thought you meant you could use it to replace the left function. That's why it had me confused.

-John

runflacruiser 19-05-2010 22:00

...I'm laughing hard now..:rotate:

I misread your "can't" for can.:bash:

Yea. I just quick typed in the example without thinking. It's not the same as the code I actually used...lol

-John

EDIT: Thanks, I did find that I used it in some other code in the FC macro. It still worked good though.

biok 21-05-2010 10:17

try this...
 
Give it a try like this
Code:

VBA.Left(string,length)
I had the same issue, and some guy in a Vba Exel forum recomend me to use the "VBA" keyWord before those string function that didn't worked for me and now it work just fine.
Hope that help you.

runflacruiser 21-05-2010 10:20

Quote:

Originally Posted by biok (Post 16532)
Give it a try like this
Code:

VBA.Left(string,length)
I had the same issue, and some guy in a Vba Exel forum recomend me to use the "VBA" keyWord before those string function that didn't worked for me and now it work just fine.
Hope that help you.

Ah. Thank you very much. Worked like a charm.
-John


All times are GMT -5. The time now is 02:31.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com