Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,561 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,894 people online right now. Registration is fast and FREE... Join Now!




Overflow error

 
Reply to this topicStart new topic

Overflow error

powellm
10 Apr, 2008 - 01:09 PM
Post #1

New D.I.C Head
*

Joined: 30 Mar, 2008
Posts: 20

vb

Private Sub cmdCount_Click()
Dim strText As String
Dim strLetter As String
Dim intNumOccurences As Integer
Dim intSearchPos As Integer
Dim intLetterPos As Integer

strText = txtText.Text
strLetter = txtLetter.Text
intNumOccurences = 0
intSearchPos = 1

Do
intLetterPos = InStr(1, strText, strLetter)
If intLetterPos > 0 Then
intNumOccurences = intNumOccurences + 1 Error occurs with this line
intSearchPos = intLetterPos + 1
End If
Loop While intSearchPos <= Len(strText) And intLetterPos <> 0

lblTimes.Caption = intNumOccurences


End Sub

*edit: Please use code tags in the future, thanks! code.gif


How do i fix the line to prevent an over flow error?

This post has been edited by Martyr2: 10 Apr, 2008 - 01:39 PM
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Overflow Error
10 Apr, 2008 - 01:38 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,213



Thanked: 217 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
An overflow error is when you run over the bounds of what a data type can hold. So to fix your problem you either need to increase the size of your data type (like to a "long") or change your design a little.

But in order to have overloaded this variable you must be chewing through quite a bit of text. Going with a long should be big enough for you to hold the value you need.

See if that works for you. smile.gif


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 11:37PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month