VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



RGCC Increment by one

by Bruce Pierson (1 Submission)
Category: Jokes/Humor
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (4 Votes)

Increments an integer by one

Code Returns
Integer

Rate RGCC Increment by one

'================================
'OK, all. Here's the first challenge,
'informally put out (without his
'knowledge or consent) by Intensify:
'================================
'--Scope of project:
'INCREMENT BY ONE
'
'--Returns:
'Value incremented by one
'
'--Challenge:
'Try to top this one, I didn't try
'TERRIBLY hard, b/c I do have a
'real job...
'
'--Constraints:
'Rule #1: "Looping for the express
'purpose of adding time to an
'algorithm is expressly forbidden."
'
'--Seriously:
'PLEASE keep these submissions in
'the 'Jokes/Humor' category to make
'sure that PSC does continue to be
'taken seriously.
'***********************************
'RGCC (Rube Goldberg Coding Contest)
'EULA:
'The code herein is copyrighted.
'
'Feel free to use this code
'in your applications. If you
'do, send payment (first month's
'lease) to me for each application
'that you distribute.
'
'You will be sent a monthly bill
'for each license of your application
'that you distribute. If you do
'not pay this bill, all licenses
'to this software will be revoked
'and Guido from the Software
'Publisher's Association will be
'paying a visit to your home.
'In addition, the users' copies of
'the software will cease to operate,
'and their virus protection software
'will be automatically deactivated.
'
'************************************
'====================
'Place this code on a form and
'add a command button
'====================
Option Explicit
Private Sub Command1_Click()
 Dim NumberThatIWantToIncrement As Integer
 NumberThatIWantToIncrement = _
   InputBox("Number to increment by 1: ", "Increment a Number")
 NumberThatIWantToIncrement = _
   IncrementAnIntegerByTheValueOfOne(NumberThatIWantToIncrement, _
   "<>")
 MsgBox NumberThatIWantToIncrement
End Sub

'====================
'Place this code in a standard module
'====================
'********************
'Requires a reference to Microsoft
'ActiveX Data Objects 2.x
'********************
Option Explicit
Public Function IncrementAnIntegerByTheValueOfOne _
(ByVal TheOriginalNumber As Integer, _
ByVal TheStringToPassInWillBeThis As String) As Integer
 Dim FirstCharacterOfTheStringPassedIn As String * 1
 Dim ASCIIValueOfTheFirstCharacterOfTheStringPassedIn As Integer
 Dim ValueOfOne As Integer
 FirstCharacterOfTheStringPassedIn = _
   GetTheFirstCharacterOfTheString(TheStringToPassInWillBeThis)
 ASCIIValueOfTheFirstCharacterOfTheStringPassedIn = _
   Asc(FirstCharacterOfTheStringPassedIn)
 ValueOfOne = _
   ASCIIValueOfTheFirstCharacterOfTheStringPassedIn - _
   (ASCIIValueOfTheFirstCharacterOfTheStringPassedIn - 1)
 IncrementAnIntegerByTheValueOfOne = TheOriginalNumber + ValueOfOne
End Function
Public Function GetTheFirstCharacterOfTheString(ByVal TheOriginalString As String) As String
 Dim StringToReturn As String * 1
 Dim TheRecordsetToHoldTheString As ADODB.RecordSet
 Set TheRecordsetToHoldTheString = New ADODB.RecordSet
 '---Note here, the clever use of the 'With' keyword to cut down on verbosity...
 With TheRecordsetToHoldTheString
  .Fields.Append "StringName", adVarChar, 100
  .Open
  .AddNew "StringName", TheOriginalString
 End With
 StringToReturn = _
   Chr(Asc(Right(TheRecordsetToHoldTheString.Fields(0).Value, _
   Len(TheRecordsetToHoldTheString.Fields(0).Value) - 1)))
 GetTheFirstCharacterOfTheString = StringToReturn
End Function

Download this snippet    Add to My Saved Code

RGCC Increment by one Comments

No comments have been posted about RGCC Increment by one. Why not be the first to post a comment about RGCC Increment by one.

Post your comment

Subject:
Message:
0/1000 characters