[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


substring(i, 5) in vb6

Posted on 2004-11-11
Medium Priority
Last Modified: 2013-12-25

I normally have to program in .NET and i love the substring function, but how do you do it in vb6 (i have to modify some old code)

My .NET code is

'Declare Variables
Dim i As Integer = 0
Dim strTemp As String = ""
Dim ConvertedValue As String = ""

'For each hex value do
For i = 0 To (value.Length - 1) step 2
       'Get the next hex value
        strTemp = value.Substring(i, 2)
        'Convert the hex value to ascii and append it to the string
        ConvertedValue = ConvertedValue & Chr(Convert.ToInt32(Val("&H" & strTemp)))
        'hex strings are 2 characters thats why 2 characters are taken at a time and why
Return ConvertedValue

so how do i get the same effect as
strTemp = value.Substring(i, 2)

I can convert the rest of the code to vb6

Question by:adam_pedley
  • 2
LVL 14

Expert Comment

by:Farzad Akbarnejad
ID: 12562525
strTemp = Mid(value, i, 2)

strTemp and Value must be string variables.


LVL 14

Accepted Solution

Farzad Akbarnejad earned 2000 total points
ID: 12562531
in .Net i is zerobased index but in VB it starts from 1 so:

strTemp = Mid(value, i + 1, 2)


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month18 days, 16 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question