Solved

Strings

Posted on 2004-08-10
9
229 Views
Last Modified: 2010-04-23
i have this application which i use a picture box to display letters (A- Z).  I used x and y coordinated to create the letters.  I am having difficulty in trying to display a word or sentence to the picture box through a text box.  Should something like a String.ToCharArray() be used to reference each individual character or a string.chars to search the string??  I am really stuck here as how to solve this.

heres an example of the letter Capital S i have created

Private Sub S(ByVal C As Integer, ByVal R As Integer)
' C - Column
' R - Row
        Dim index As Integer
        Dim I As Integer

        'S-------------------------------------------------------------------
        For index = 0 To 2
            myRoadSign.SetLight(C, 1 + index + R, True)
        Next
        For I = 1 To 3
            myRoadSign.SetLight(C + I, 0 + R, True)

        Next
        myRoadSign.SetLight(C + I, 1 + R, True)

        For I = 0 To 2
            myRoadSign.SetLight(C + 4, I + 5 + R, True)

        Next
        For I = 1 To 3
            myRoadSign.SetLight(C + I, 8 + R, True)

        Next
        myRoadSign.SetLight(C + 0, 7 + R, True)
        For I = 1 To 3
            myRoadSign.SetLight(C + I, 4 + R, True)
        Next

    End Sub

I call the function like this with hard coded values Call S(11, 36 )
below is a small function to test if the letter is uppercase and then calls the S function dynamically.  this obviously doens't work

 Public Sub WLBoard(ByVal text As String)
Dim i As Integer = 0
While i <> -1
If text(i) = "S" Then ' error
upperA(xpos, ypos)
End If
End While
End Sub

I want to display the words or sentences dynamically.  Any help will be very much appreciated.  

gbilios


0
Comment
Question by:gbilios
  • 6
  • 3
9 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 130 total points
ID: 11769897
To access the individual characters in a string iteratively you would do something like this:

Public Sub WLBoard(ByVal text As String)
    Dim i As Integer
    Dim c As String
    For i = 0 To text.Length - 1
        c = text.Substring(i, 1)
        If c.equals("S") Then
            upperA(xpos, ypos)
        End If
    Next i
End Sub
0
 

Author Comment

by:gbilios
ID: 11769926
i appreciate your quick reply.  So if i added if else statements  for the entire alphabet, then me typing in a word would be displayed exactly as i have typed it in the textbox?

upperA(xpos, ypos)  'xpos is Columns and ypos is Rows

I have experimented with various ways but the most simplest would be

Col = Col + 6 ' moves the entire letter to the next column

I added 6 because i dont want the letters to sit ontop of each other.  Is there a function to detect spaces so that i can write sentences in the picture box.

Would there be an additional for loop to allow the x and y coordinates to be done dynamically instead of me hard coding it like this

upperA(0,36)

0
 

Author Comment

by:gbilios
ID: 11770154
i must of missed something . i modified the line of code :

upperA(xpos, ypos) to upperA(i*6, ypos)

This allows me to enter words and sentences.  prior doing this, there was no way telling or no way the characters or words would form without the column(s) incrementing .

i appreciate all your help

thank-you

gbilios
0
 

Author Comment

by:gbilios
ID: 11770864
I have one more query with the following code
Dim i As Integer
    Dim c As String
    For i = 0 To text.Length - 1
        c = text.Substring(i, 1)
        If c.equals("S") Then
            upperA(xpos, ypos)
        End If
    Next i
End Sub

i changed it to

   If c.Equals("A") Then
         Call A(col, row)

           col = col + 6
  else If col > 76 Then
            col = 0
                row = row + 11
            End If

The line Call A(col, row)

enables lines to be displayed when the text too long
With this modified code i am unable to enter spaces
if i change the line Call A(i*6) then that solves it but does not allow me to have multiple lines

Can anyone please help
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 11772248
What is the difference between upperA() and A()?

Can you post some more complete code?  I'm sure we can get it working...

Idle_Mind
0
 

Author Comment

by:gbilios
ID: 11773679
Sorry for the missunderstabding
the program does the basic things which is display the characters to the picture box

for example the sentence above and i keep typing till the end of the line , i should automatically goto the next line the code that does this is

if col > 76 then
row = row + 11 'goto next line 11 rows down
col = 0 ' set column to position 0

A is Upper and lower which i am still doing is lowerA

Private Sub A(ByVal C As Integer, ByVal R As Integer) ' okay, should be upperA
        Dim index As Integer
        Dim I As Integer

        'A-------------------------------------------------------------------

        For index = 0 To 7
            myRoadSign.SetLight(C, 1 + index + R, True)
            myRoadSign.SetLight(C + 4, 1 + index + R, True)

        Next
        For I = 1 To 3
            myRoadSign.SetLight(C + I, 0 + R, True)
        Next

        For I = 1 To 3
            myRoadSign.SetLight(C + I, 4 + R, True)
        Next

    End Sub

    Private Sub lowerA(ByVal C As Integer, ByVal R As Integer)
        Dim index As Integer
        Dim I As Integer

        'a-------------------------------------------------------------------
        For index = 0 To 3

            myRoadSign.SetLight(C + 4, 5 + index + R, True)

        Next

        For index = 0 To 2


            myRoadSign.SetLight(C, 5 + index + R, True)

        Next
        For I = 0 To 2
            myRoadSign.SetLight(C + 1 + I, 4 + R, True)

        Next
        For I = 0 To 1
            myRoadSign.SetLight(C + 1 + I, 4 + R, True)
            myRoadSign.SetLight(C + 1 + I, 8 + R, True)
        Next
        myRoadSign.SetLight(C + 3, 7 + R, True)
       

    End Sub
0
 

Author Comment

by:gbilios
ID: 11773758
i accidentally hity the tab button , got sent without me finishing it

the previous message with the both uppercase and lowercase characters are created using x,y coordinates (columns and rows).

Public Sub WLBoard(ByVal text As String)
        Dim i As Integer
        Dim c As String
        Dim row As Integer = 0 ' Set the Row position to zero
        Dim col As Integer = 0 ' Set the Column position to zero

        For i = 0 To text.Length - 1

            c = text.Substring(i, 1)
            If col > 76 Then
                Call A(col, row)
                row = row + 11
                col = 0
            End If

            If c.Equals("A") Then

                Call A(col, row)

                col = col + 6

            End If

            If c.Equals("a") Then

                Call lowerA(col, row)

                col = col + 6

            End If
At this point i am worrying getting the basics done which is displaying text like i wrote this sentence.  
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 11775806
This what you looking for?

    Public Sub WLBoard(ByVal text As String)
        Dim i As Integer
        Dim c As String
        Dim row As Integer = 0 ' Set the Row position to zero
        Dim col As Integer = 0 ' Set the Column position to zero

        For i = 0 To text.Length - 1
            c = text.Substring(i, 1)
            Select Case c
                Case "A"
                    Call A(col, row)
                Case "a"
                    Call lowerA(col, row)
                Case "B"
                    Call B(col, row)
                Case "b"
                    Call lowerB(col, row)

                    ' add more Case statements for
                    ' all of your other letters in here

                Case Else
                    MsgBox(c, MsgBoxStyle.Information, "Undefined Letter")
            End Select
            col = col + 6
            If col > 76 Then
                row = row + 11
                col = 0
            End If
        Next i
    End Sub
0
 

Author Comment

by:gbilios
ID: 11780674
That is precisely what i did.  Creating the letters and getting them to the picture box wasn't the problem.  It was 'spaces' and the carriage returns i was having problems.    
I solved that problem (spaces & CR) and it was alot simple than i thought.  I worked out exactly what needed to be done.  
I added the if statement
if c.Equals(" ") ' if its a space then add a space
   col = col + 6 ' go six columns to the right
end if

or the case statement

case " "
  col = col + 6

i appreciate your help.

0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

758 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now