PC Review


Reply
Thread Tools Rate Thread

Chopping a variable letter off the end of a word

 
 
BTU_needs_assistance_43
Guest
Posts: n/a
 
      1st Jul 2009

So I discovered that not all my reports will go in order and sometimes they
will end with "a", "b", "c", or "d" instead of just "a". I had a working
program set up to chop off "a" if it was at the end. But now that I have
rewritten it to include more letters, the program still gives an output value
but never chops anything at all off the letter and I'm trying it with both an
If Then Else statement and an If Then Goto Else Goto statement. The program
runs successfully but gives the same wrong output both ways. Is my logic
faulty in this program? Can I not interlace functions like this? What is the
deal!?

IF/THEN/ELSE:

If Right(B62, 1) = "a" Then
rst![Total Shot Name] = Left([vShots], Len(vShots) - 1)
Else
If Right(B62, 1) = "b" Then
rst![Total Shot Name] = Left([vShots], Len(vShots) - 1)
Else
If Right(B62, 1) = "c" Then
rst![Total Shot Name] = Left([vShots], Len(vShots) - 1)
Else
If Right(B62, 1) = "d" Then
rst![Total Shot Name] = Left([vShots], Len(vShots) - 1)
Else
rst![Total Shot Name] = vShots
End If
End If
End If
End If



IF/THENGOTO/ELSEGOTO

If Right(B62, 1) = "a" Then GoTo CutShort Else GoTo Checkforb
Checkforb: If Right(B62, 1) = "b" Then GoTo CutShort Else GoTo Checkforc
Checkforc: If Right(B62, 1) = "c" Then GoTo CutShort Else GoTo Checkford
Checkford: If Right(B62, 1) = "d" Then GoTo CutShort Else GoTo SameName
CutShort: rst![Total Shot Name] = Left([vShots], Len(vShots) - 1)
SameName: rst![Total Shot Name] = vShots
rst.Update
 
Reply With Quote
 
 
 
 
Jack Leach
Guest
Posts: n/a
 
      1st Jul 2009

You might try the Select Case statement instead.

Select Case Right(B62, 1)
Case "a"
Dosomething
Case "b"
Dosomething
Case Else
Dosomethingelse
End Select.

Or maybe an If/Then/Elseif:

If Right(B62, 1) = "a" Then
DoSomething
ElseIf Right(B62, 1) = "b" Then
DoSomething
ElseIf Right (B62, 1) = "c" Then
DoSomething
Else
DoSomethingelse
End If

This is sometimes preferable to nested if statements.

hth
--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)



"BTU_needs_assistance_43" wrote:

> So I discovered that not all my reports will go in order and sometimes they
> will end with "a", "b", "c", or "d" instead of just "a". I had a working
> program set up to chop off "a" if it was at the end. But now that I have
> rewritten it to include more letters, the program still gives an output value
> but never chops anything at all off the letter and I'm trying it with both an
> If Then Else statement and an If Then Goto Else Goto statement. The program
> runs successfully but gives the same wrong output both ways. Is my logic
> faulty in this program? Can I not interlace functions like this? What is the
> deal!?
>
> IF/THEN/ELSE:
>
> If Right(B62, 1) = "a" Then
> rst![Total Shot Name] = Left([vShots], Len(vShots) - 1)
> Else
> If Right(B62, 1) = "b" Then
> rst![Total Shot Name] = Left([vShots], Len(vShots) - 1)
> Else
> If Right(B62, 1) = "c" Then
> rst![Total Shot Name] = Left([vShots], Len(vShots) - 1)
> Else
> If Right(B62, 1) = "d" Then
> rst![Total Shot Name] = Left([vShots], Len(vShots) - 1)
> Else
> rst![Total Shot Name] = vShots
> End If
> End If
> End If
> End If
>
>
>
> IF/THENGOTO/ELSEGOTO
>
> If Right(B62, 1) = "a" Then GoTo CutShort Else GoTo Checkforb
> Checkforb: If Right(B62, 1) = "b" Then GoTo CutShort Else GoTo Checkforc
> Checkforc: If Right(B62, 1) = "c" Then GoTo CutShort Else GoTo Checkford
> Checkford: If Right(B62, 1) = "d" Then GoTo CutShort Else GoTo SameName
> CutShort: rst![Total Shot Name] = Left([vShots], Len(vShots) - 1)
> SameName: rst![Total Shot Name] = vShots
> rst.Update

 
Reply With Quote
 
John Spencer MVP
Guest
Posts: n/a
 
      1st Jul 2009

Well, it would help if you posted the entire procedure instead of a snippet.

Also, you should be able to change the snippet to

IF B62 Like "*[abcd]" Then
rst![Total Shot Name] = Left(vShots,Len(vShots)-1)
End IF

So are you saving the change in the value with
Rst.Update
which permanently changes the value in the table

What values are in vShots and B62? Are these fields in the recordset are
variables in your code?


John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

BTU_needs_assistance_43 wrote:
> So I discovered that not all my reports will go in order and sometimes they
> will end with "a", "b", "c", or "d" instead of just "a". I had a working
> program set up to chop off "a" if it was at the end. But now that I have
> rewritten it to include more letters, the program still gives an output value
> but never chops anything at all off the letter and I'm trying it with both an
> If Then Else statement and an If Then Goto Else Goto statement. The program
> runs successfully but gives the same wrong output both ways. Is my logic
> faulty in this program? Can I not interlace functions like this? What is the
> deal!?
>
> IF/THEN/ELSE:
>
> If Right(B62, 1) = "a" Then
> rst![Total Shot Name] = Left([vShots], Len(vShots) - 1)
> Else
> If Right(B62, 1) = "b" Then
> rst![Total Shot Name] = Left([vShots], Len(vShots) - 1)
> Else
> If Right(B62, 1) = "c" Then
> rst![Total Shot Name] = Left([vShots], Len(vShots) - 1)
> Else
> If Right(B62, 1) = "d" Then
> rst![Total Shot Name] = Left([vShots], Len(vShots) - 1)
> Else
> rst![Total Shot Name] = vShots
> End If
> End If
> End If
> End If
>
>
>
> IF/THENGOTO/ELSEGOTO
>
> If Right(B62, 1) = "a" Then GoTo CutShort Else GoTo Checkforb
> Checkforb: If Right(B62, 1) = "b" Then GoTo CutShort Else GoTo Checkforc
> Checkforc: If Right(B62, 1) = "c" Then GoTo CutShort Else GoTo Checkford
> Checkford: If Right(B62, 1) = "d" Then GoTo CutShort Else GoTo SameName
> CutShort: rst![Total Shot Name] = Left([vShots], Len(vShots) - 1)
> SameName: rst![Total Shot Name] = vShots
> rst.Update

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
When I type a letter...the next letter disappears /Microsoft word Gray Microsoft Word Document Management 1 4th Mar 2010 02:25 AM
search for lowercase letter in two-letter 'word' ppeer Microsoft Excel Programming 4 16th Feb 2010 03:10 AM
Default Capital letter for 1st letter of a word =?Utf-8?B?SmVmZg==?= Microsoft Excel Misc 6 10th Jul 2006 08:36 AM
word replaced or letter changed removes the next letter word?? =?Utf-8?B?d29yZCByZXBsYWNlbWVudD8=?= Microsoft Access Queries 1 4th May 2005 03:39 AM
convert from small letter to capital letter in word or excel =?Utf-8?B?bWFuZ28=?= Microsoft Excel Worksheet Functions 2 14th Jun 2004 03:56 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:49 PM.