Solved

replacing text in a textbox with pictures

Posted on 2003-11-27
4
471 Views
Last Modified: 2010-05-01
id like to make a program that converts a string to hiragana, i have all the pictures but i just need a piece of code that can replace tow or three characters at a time in a rich text box.

hitori ja nai yo

() means that its picture so it will become
(HI)(TO)(RI) (JA) (NA)(I) (YO)

kono mama, atenado nakute ii
(KO)(NO) (MA)(MA), (A)(TE)(NA)(DO) (NA)(KU)(TE) (I)(I)

as you can see it replaces the text with pictures, is this possible
0
Comment
Question by:Tai-San
  • 2
4 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9833647
listening...
0
 
LVL 6

Expert Comment

by:mirzas
ID: 9837300
Yes.. could you post a list of all letter combinations that will be replaced by a picture.

There is an easy way to do this.
Rename all the pictures to the strings they represent eg. (KO) should be KO.bmp
and put them in the same directory

This code has no error handling, will work only if images exist in the given path
and if valid input strings are given in Text1

Option Explicit
Const IMAGES_DIRECTORY = "C:\images\"
Const iImageW = 32
Const iImageH = 32

Private Sub Command1_Click()
    Dim x As Integer
    Dim y As Integer
    Dim i As Integer
    Dim tempBfr As String
   
    x = 1
    y = iImageH  'picture height
   
    tempBfr = ""
    For i = 1 To Len(Text1.Text)
        tempBfr = tempBfr & Mid(Text1.Text, i, 1)
        If FileExists(IMAGES_DIRECTORY & tempBfr) Then
            Picture1.PaintPicture LoadPicture("C:\a.bmp"), x, y
            tempBfr = ""
            x = x + iImageW
            'y remains the same if you place picures side by side
        End If
    Next
End Sub


Private Function FileExists(sFile As String) As Boolean
     If UCase(Dir(sFile)) = UCase(sFile) Then
      FileExists = True
    Else
      FileExists = False
    End If
End Function
0
 
LVL 6

Accepted Solution

by:
mirzas earned 125 total points
ID: 9837305
Ups! I made a mistake

the Line

 Picture1.PaintPicture LoadPicture("C:\a.bmp"), x, y


should be

 Picture1.PaintPicture LoadPicture(IMAGES_DIRECTORY & tempBfr), x, y

Sorry
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 9838253
Took a little while to come up with a working example. In the below example, you'll need to change the following constants to test it for yourself: ImageDir, ImageExt, Image1, Image2 and Image3. You may also want to add more constants of Image* (*=#) or use an array. The below example selects the word it found an image to, and replaces it by pasting the image for it.

Form1:
---------------

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Const WM_PASTE = &H302

Private Const ImageDir As String = "C:\Program Files\Microsoft Visual Studio\Common\Graphics\Bitmaps\Assorted\"
Private Const ImageExt As String = ".bmp"
Private Const Image1 As String = "club"
Private Const Image2 As String = "cup"
Private Const Image3 As String = "hand"
Private Sub Form_Load()
    RichTextBox1.Text = ""
End Sub
Private Sub RichTextBox1_Change()
    Call ConvertWords(RichTextBox1)
End Sub
Private Sub ConvertWords(ByVal RichTextBox As RichTextBox)
    Dim strArray() As String, iLoop As Integer, iStart As Integer, iEnd As Integer
    strArray = Split(RichTextBox.Text, " ")
    For iLoop = LBound(strArray) To UBound(strArray)
        iEnd = iEnd + Len(strArray(iLoop)) + IIf(iLoop < UBound(strArray), 1, 0)
        iStart = iEnd - Len(strArray(iLoop))
        Select Case LCase(strArray(iLoop))
            Case Image1
                RichTextBox.SelStart = iStart
                RichTextBox.SelLength = iEnd
                Call PasteImage(ImageDir & Image1 & ImageExt, RichTextBox.hwnd)
            Case Image2
                RichTextBox.SelStart = iStart
                RichTextBox.SelLength = iEnd
                Call PasteImage(ImageDir & Image2 & ImageExt, RichTextBox.hwnd)
            Case Image3
                RichTextBox.SelStart = iStart
                RichTextBox.SelLength = iEnd
                Call PasteImage(ImageDir & Image3 & ImageExt, RichTextBox.hwnd)
        End Select
    Next iLoop
End Sub
Private Sub PasteImage(ByVal strPath As String, ByVal lHandle As Long)
    Clipboard.Clear
    Call Clipboard.SetData(LoadPicture(strPath))
    Call SendMessage(lHandle, WM_PASTE, 0, 0)
End Sub

-----------

If you have the folder (VS6) I used for testing, then you can test it by typing one of the Image* strings such as "club", "cup" or "hand". When you space it, the word will be replaced by the image.  This may be what you're looking for, if not, sorry. :)
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

747 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

13 Experts available now in Live!

Get 1:1 Help Now