Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Help with a little error..


  • Please log in to reply

#1
TehJoJo

TehJoJo

    New Member

  • Member
  • Pip
  • 2 posts
I spent a while tryng to figure this out. eh. I figure i'll ask some fellow programmers.

                       [1]   buf = Left(sArray(counter), 12)
                        [2]   I = InStr(buf, " ")
                        [3]   a = I - 2
                        [4]   name = Left(buf, a)
I get a "Run Time Error '5' - Invalid procedure call or argument" on line 4 (the numbers in the code box are the lines.

Anyone know what the problem is? From what I know, it should work.
  • 0

Advertisements


#2
stu_design

stu_design

    Member

  • Member
  • PipPipPip
  • 217 posts
what r u trying to do

give us what ur doing, what language etc

littyle more info be appreciated
  • 0

#3
scicatur

scicatur

    Member

  • Member
  • PipPip
  • 16 posts
String processing at runtime has its own special stumbling stones. If the programmer correctly anticipates them the result is a code that takes in account all possibilities considering the string.

The problem is this: You create a string buffer that has 12 characters and it is created from some sArray(counter) ... now it is not certain (and as programmer you should never assume it to be 100% certain) what exactly the string contents are.

[edited ...v.2]
Say that the 'buf' is " some funny bunny " .. then your [2] line makes I = 1 . (Because of the leading white space)
after this 'a' becomes - 1 . In your code line [4] makes a runtime error because your code attempts to take substring from 'buf' using negative length. Computers will never try to understand paradoxes and so you get the errors.
[/edited]

Now you should probably anticipate what you want to do if your buffer 'buf' contents are something else from what you expected.

Some General Ideas:
- firstly trim all your strings. Trimming means that you cut away all leading as well as all tailing white space characters from your string. I think VB has a function for this purpose

-secondly check the values of critical variables using if-statements. Like before the line [4] you should check in if-statement what is the value of 'a'. Then you make your code handle the situation when the value is out of accepted range.

PS. would be helpful if you mentioned the language in your post like stu_design mentioned. I guessed that you use VB and checked your functions with google but still helpful if you mention.

Edited by scicatur, 03 June 2005 - 11:42 AM.

  • 0

#4
TehJoJo

TehJoJo

    New Member

  • Topic Starter
  • Member
  • Pip
  • 2 posts
Yes, i got it to work. I was because a few of the strings in the array didnt have a space, so it made integer a negative.
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP