Link to home
Start Free TrialLog in
Avatar of luthar
luthar

asked on

How to get the 3rd character in a string

Well the title says it all

Let's say i have the string: "abcdefg"
i want to get the 3rd character (ie: "c") what is the function to do so?

This shouln't be too difficult to do
i know in excel the STXT function does it

TIAFYT (thanks in advance for your time)

Luthar
Avatar of luthar
luthar

ASKER

Edited text of question.
ASKER CERTIFIED SOLUTION
Avatar of schworak
schworak

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of luthar

ASKER

Good comment but here's my code:
Option explicit
Dim Nbr_de_coup as integer

Private Sub Form_load()
Genere_La_Solution (Nbr_de_coup)
End sub
----------------------------------
Public Function Genere_La_Solution(ByVal Nbr_de_Case)

Dim x As Integer
Dim Nbr_Genere As String


    For x = 0 To Nbr_de_Case
        Let Nbr_Genere = Int(Rnd() * 5)
        Solution = Solution & Nbr_Genere
    Next x
   
End Function
------------------------------------
Public Sub Label1_Click(Index As Integer)
Dim i As Integer

Nbr_de_coup = Nbr_de_coup + 1

For i = 1 To Len(Solution)
Reponse = Mid(Solution, i, 1)
If Reponse <> Index Then
    MsgBox "Vous avez pousser une mauvaise touche!", vbOKOnly, "Que c'est dommage!"
    Exit Sub
End If
Next i
-----------------------------------

I get an error at the If Response <>...

Any suggestion?
RESPONSE is a STRING, INDEX is an INTEGER. You can't compare an Integer to a String and get meaningful results...

M
Is this what you are trying to do?
'...
i = InStr(1, solution, Format(Index))
If i <> Index Then
    MsgBox "Vous avez pousser une mauvaise touche!", vbOKOnly, "Que c'est dommage!"
    Exit Sub
End If
'...
Avatar of luthar

ASKER

Sounds more like it but the only problem is that I need the result to be different than 0 or 1 cause i have 5 label in the control array...
I'm gonna put more points cause i think it's worth more :D
To convert a integer to a string use STR$(num). To convert from a string to a number use VAL("string").