Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
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