:D snasui.com ยินดีต้อนรับ :D
ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย :thup: สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ :arrow: ระบุ Version ของ Excel
:!: โปรดทราบ :!:
  1. กรุณาอ่านกฎการใช้บอร์ด (Forum rules) ในตำแหน่งด้านบนของแต่ละบอร์ด
  2. การสมัครสมาชิก การ Login การกู้คืนรหัสผ่าน
    1. สมัครสมาชิกดูขั้นตอนได้ที่ :arrow: สมัครสมาชิก
    2. Login เข้าระบบโดยคลิกปุ่ม Login ตรงมุมขวาบนของหน้านี้ :roll:
    3. การ Login ผ่าน Facebook ดูวิธีที่ :arrow: Login ผ่าน Facebook
    4. ลืมรหัสผ่านสามารถรับรหัสใหม่ได้ที่ :arrow: Reset รหัสผ่าน
  3. มีปัญหาการใช้งาน แจ้งผู้ดูแลระบบได้ที่ :arrow: ติดต่อผู้ดูแลระบบ
  4. กำหนดการตั้งค่าส่วนตัว เช่นตั้งค่าภาษาเป็นไทยหรืออังกฤษดูได้ที่ :arrow: ตั้งค่าส่วนตัว
  5. การตั้งและตอบกระทู้ดูได้ที่ :arrow: วิธีการตั้งและตอบกระทู้
  6. การจัดรูปแบบตัวอักษรด้วย bbcode ในช่องแสดงความคิดเห็นดูได้ที่ :arrow: จัดรูปแบบตัวอักษร
  7. กำหนดขนาดตัวอักษรใน Browser ดูได้ที่ :arrow: กำหนดขนาดตัวอักษรใน Browser

อยากทราบวิธีตัดช่องว่างใน VBA

Forum rules
  1. ไม่อนุญาตให้ใช้ภาษาแชทในการถามและตอบปัญหา ไม่ใช้คำว่า "คับ" หรือ "อ่ะครับ" แทนคำว่า "ครับ" ไม่ใช้คำว่า "เด๋ว" แทนคำว่า "เดี๋ยว" เป็นต้น เนื่องจากเมื่อแปลเป็นภาษาต่างประเทศแล้วจะให้ความหมายผิดไปจากที่ควรจะเป็น
  2. ห้ามถามโดยระบุชื่อผู้ตอบและต้องตั้งชื่อกระทู้ให้สื่อถึงปัญหาที่จะถาม ไม่ตั้งชื่อว่า ช่วยด้วยครับ, มีปัญหามาปรึกษาครับ เป็นต้น
  3. กรุณาอธิบายปัญหาและระบุคำตอบที่ต้องการมาในกระทู้ด้วยเสมอถึงแม้จะอธิบายไว้ในไฟล์แนบแล้วก็ตาม ทั้งนี้เพื่ออำนวยความสะดวกแก่เพื่อนสมาชิกในการค้นหาข้อมูล
  4. กรุณาแนบไฟล์ตัวอย่างพร้อมแสดงคำตอบที่ถูกต้องมาในไฟล์ด้วยเพื่อให้ง่ายต่อการทำความเข้าใจและสะดวกต่อการตอบคำถาม (ขนาดไฟล์ไม่เกิน 500Kb ขนาดภาพไม่เกิน 800*600 Pixel) ไม่แนบเป็น Link มาจากแหล่งอื่นที่อาจจะถูกลบทิ้งไปโดยต้นทางในภายหลัง นอกจากนี้ไม่ควรแนบไฟล์ที่มีข้อมูลสำคัญอันก่อให้เกิดความเสียหายกับตนเองและผู้อื่น
  5. กรณีเป็นคำถามเกี่ยวกับ Programming เช่น VBA, VB.Net, C#, SQL ฯลฯ ต้องลองเขียนมาเองก่อนเสมอ ถามเฉพาะที่ติดปัญหา ระบุ Module, Procedure ที่ติดปัญหาให้ชัดเจน กรุณาโพสต์ Code ให้แสดงเป็น Code คือเปิดด้วย [code] และปิดด้วย [/code] ตัวอย่างเช่น [code]dim r as range[/code] เพื่อให้แตกต่างจากข้อความทั่วไป สะดวกในการอ่านและทดสอบ (คลิกเพื่อดูตัวอย่าง)
  6. กรุณาแจ้งผลการใช้งานเมื่อได้รับคำตอบว่าตรงกับความต้องการหรือไม่

Post a reply


This question is a means of preventing automated form submissions by spambots.
Smilies
:D :thup: :cp: :flw: :rz: :sg: :tt: :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :arrow: :ard: :arl: :aru: :| :mrgreen: :geek: :ugeek:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: อยากทราบวิธีตัดช่องว่างใน VBA

Re: อยากทราบวิธีตัดช่องว่างใน VBA

#31

by hydrotaxonomy » Mon Jul 23, 2012 11:59 pm

ขอบคุณคะ

Re: อยากทราบวิธีตัดช่องว่างใน VBA

#30

by snasui » Mon Jul 23, 2012 11:24 pm

:D ลองลบค่าต่าง ๆ ในบรรทัดที่ 1:28 ในชีท Crypto ทิ้งไปแล้ว Run Code ด้านล่างดูครับ

Code: Select all

Public Sub Crypto()
    ''''''''''''''''''''''''''''' Declarations variable'''''''''''''''''''''''''''''''''''''''
    Dim Key As String, Message As String, PlainText As String, Longkey As String
    Dim encode As String, Decode As String, EnCol As String, EnRow As String
    Dim i As Integer, p As Integer, r As Integer, c As Integer
    Dim l As Integer, a(1 To 26, 1 To 26) As Variant, ta As Variant, tb(1 To 26) As Variant
    Dim m As Integer, t As String, n As Integer, o As Integer
    ta = Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", _
        "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z")
    t = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    t = Application.Rept(t, 2)
    For l = 1 To 26
        For m = 1 To 26
            a(l, m) = Mid(t, m + n, 1)
        Next m
        n = n + 1
    Next l
    Key = InputBox("Enter the key of encryption") ' get Key
    Key = UCase(Key)  ' change all key to uppercase letters
    Message = InputBox("Enter the message that you want to send") ' get Message
    Message = LCase(Message) ' change all message to lowercase letter
    PlainText = Replace(Message, " ", "") ' cut space in Message by replacement and put into variable(Plaintext)
    Longkey = Left(Application.WorksheetFunction.Rept(Key, 10), Len(PlainText)) ' cut letter from left of Right_plaintext
    MsgBox ("Key = " & Key)  ' show key
    Worksheets("Crypto").Range("B29").Value = Key 'Set the value to the cell of the range"B29"
    MsgBox ("Message = " & Message) ' show message
    Worksheets("Crypto").Range("B30").Value = Message 'Set the value to the cell of the range"B30"
    MsgBox ("PlainText = " & PlainText) ' show Plaintext
    Worksheets("Crypto").Range("B31").Value = PlainText  'Set the value to the cell of the range"B30"
    MsgBox ("Longkey = " & Longkey) ' show long key
    Worksheets("Crypto").Range("B32").Value = Longkey 'Set the value to the cell of the range"B31"
    
    ''''''''''''''''''''''''''''''''' Encode ''''''''''''''''''''''''''''''''''''''''''''''
    p = 1
    For i = 1 To Len(Message)     ' Loop for Encode
        EnCol = Mid(Message, i, 1) ' Sub Message
        If EnCol = " " Then  ' Check if Sub Message equal space Add space to encode
            encode = encode + " "
            p = p - 1
        Else
            EnRow = Mid(Longkey, p, 1) ' Sub Longkey
            r = Application.Match(EnRow, ta, 0) 'find EnRow in column A return Index
            r = r + 1  'Not Found row A1
            c = Application.Match(EnCol, ta, 0) 'find EnCol in row And return Index
        encode = encode + a(r - 1, c) 'return the value to the cell
        End If
        p = p + 1
    Next i
    Worksheets("Crypto").Range("b33").Value = encode 'Set the value to the cell of the range"B33"
    MsgBox ("Encode = " & encode) ' show Encode
    '''''''''''''''''''''''''''''''''''''''''''Decode''''''''''''''''''''''''''''''''
    p = 1
    For i = 1 To Len(Message) ' Loop for Encode
        EnCol = Mid(encode, i, 1) ' Sub Encode
        If EnCol = " " Then ' Check if Sub Encol equal space Add space to encode
            Decode = Decode + " "
            p = p - 1
        Else
            EnRow = Mid(Longkey, p, 1) ' Sub Longkey
            r = Application.Match(EnRow, ta, 0) 'find EnRow in column A return Index
            r = r + 1 'Not Found row A1
            For o = 1 To 26
                tb(o) = a(r, o)
            Next o
            c = Application.Match(EnCol, tb, 0) + 1 'find Encol in row
            Decode = Decode + a(1, c)
        End If
        p = p + 1
    Next i
    Worksheets("Crypto").Range("b34").Value = LCase(Decode) 'Set the value to the cell of the range"B34"
    MsgBox ("Decode = " & Decode) ' show Decode
    'Restore the original style.("Normal" is a name for the default style.)
    MsgBox ("Formatting has been applied")
    Range("B29:B34").ClearContents
    Range("B29:B34").Style = "Normal"
    MsgBox ("Original formatting")
End Sub

Re: อยากทราบวิธีตัดช่องว่างใน VBA

#29

by hydrotaxonomy » Mon Jul 23, 2012 9:31 pm

ไฟล์นี้คะ ขอบคุณคะ
Attachments
Test 1.xls
(45 KiB) Downloaded 18 times

Re: อยากทราบวิธีตัดช่องว่างใน VBA

#28

by hydrotaxonomy » Mon Jul 23, 2012 9:29 pm

นี่คือค่าทั้งหมด ที่ต้องการให้แสดงคะ

มีเพียงค่า encode กับ decode เท่านั้นคะ ที่ต้องแสดงใน worksheets ก่อนแล้วจึงมาแสดงใน msgbox
ส่วนค่าเหลือมีตัวแปรเก็บไว้ดูได้นะคะ
Attachments
vba8.jpg
vba8.jpg (18.27 KiB) Viewed 200 times

Re: อยากทราบวิธีตัดช่องว่างใน VBA

#27

by snasui » Mon Jul 23, 2012 9:24 pm

:D มีค่าใดบ้างที่ไม่ต้องเขียนให้ Worksheet ก่อน ช่วยอธิบายรายละเอียดเพิ่มเติมหรือจับภาพมาให้ดูด้วยครับ จาก Code ที่เขียนมาล่าสุดมีการบันทึกค่าลงไปใน Worksheet ด้วย ช่วยแนบไฟล์ตัวอย่างนั้นมาด้วยจะได้ทำความเข้าใจได้สะดวกครับ

Re: อยากทราบวิธีตัดช่องว่างใน VBA

#26

by hydrotaxonomy » Mon Jul 23, 2012 9:07 pm

คือในโค้ด ต้องไปเขียนค่าใน worksheets ก่อนนะคะ แล้วถึงเรียกตัวแปรนั้นมาแสดงบน msgBox นะคะ

หนูไม่ต้องการให้ แสดงค่าใน worksheets นะคะ แต่หนูไม่รู้ว่าต้องเขียนอย่างไร

Re: อยากทราบวิธีตัดช่องว่างใน VBA

#25

by snasui » Mon Jul 23, 2012 8:19 pm

:D แสดงผลเป็น Message ในลักษณะใดครับ ใน Code ที่เขียนมานั้น การแสดงเป็น Message Box ก็เขียนเป็นอยู่แล้วนี่ครับ

Re: อยากทราบวิธีตัดช่องว่างใน VBA

#24

by hydrotaxonomy » Mon Jul 23, 2012 8:12 pm

Code: Select all

Option Explicit
Public Sub Crypto()

Dim Key As String, Message As String, PlainText As String, Longkey As String, encode As String, _
      Decode As String, EnCol As String, EnRow As String
Dim i As Integer, p As Integer, r As Integer, c As Integer
    
Key = InputBox("Enter the key of encryption") 
Key = UCase(Key) 
Message = InputBox("Enter the message that you want to send")
Message = LCase(Message)
PlainText = Replace(Message, " ", "")
Longkey = Left(Application.WorksheetFunction.Rept(Key, 10), Len(PlainText))
MsgBox ("Key = " & Key) 
Worksheets("Sheet1").Range("B29").Value = Key
MsgBox ("Message = " & Message) ' show message
Worksheets("Sheet1").Range("B30").Value = Message 
MsgBox ("PlainText = " & PlainText) ' show Plaintext
Worksheets(Sheet1").Range("B31").Value = PlainText  
MsgBox ("Longkey = " & Longkey) ' show long key
Worksheets("Sheet1").Range("B32").Value = Longkey

p = 1
For i = 1 To Len(Message)   
        EnCol = Mid(Message, i, 1) 
            If EnCol = " " Then 
                encode = encode + " "
                p = p - 1
            Else
                EnRow = Mid(Longkey, p, 1)
                r = Application.Match(EnRow, Range("A2:A27"), 0)
                r = r + 1 
                c = Application.Match(EnCol, Range("A1:Z1"), 0) 
        encode = encode + Worksheets("Crypto").Cells(r, c).Value 
        End If
        p = p + 1
Next i
Worksheets("Crypto").Range("b33").Value = encode 
MsgBox ("Encode = " & encode) 

p = 1
For i = 1 To Len(Message) 
        EnCol = Mid(encode, i, 1)
            If EnCol = " " Then 
                Decode = Decode + " "
                p = p - 1
            Else
                EnRow = Mid(Longkey, p, 1) 
                r = Application.Match(EnRow, Range("A2:A27"), 0) 
                r = r + 1 'Not Found row A1
                c = Application.Match(EnCol, Range(Cells(r, 1), Cells(r, 26)), 0) 
        Decode = Decode + Worksheets("Crypto").Cells(1, c).Value  
        End If
        p = p + 1
Next i
Worksheets("Crypto").Range("b34").Value = Decode 
MsgBox ("Decode = " & Decode) 

MsgBox ("Formatting has been applied")
Range("B29:B34").ClearContents
Range("B29:B34").Style = "Normal"
MsgBox ("Original formatting")
End Sub

คือหนูอยากให้แสดงผล เป็นแบบ msgbox แต่หนูไม่รู้จะทำยังไงนะคะ

Re: อยากทราบวิธีตัดช่องว่างใน VBA

#23

by snasui » Mon Jul 23, 2012 5:47 pm

:D ตอบไปตามที่เข้าใจนะครับ คือต้องการให้ Decode มีจำนวนอักขระเท่า Encode วรรคให้เปลี่ยนเป็นเครื่องหมาย _ (Underscore)

ลองดูตัวอย่าง Code ตามด้านล่างครับ

Code: Select all

Public Sub Crypto01()
    Dim Key As String, PlainText As String, tempText As String
    Dim Longkey As String, Encode As String, Decode As String
    Dim t As String, i As Integer
    Key = InputBox("Enter the key of encryption")
    Key = UCase(Key)
    tempText = InputBox("Enter the message that you want to send")
    PlainText = Replace(tempText, " ", "")
    Longkey = Left(Application.Rept(Key, 10), Len(PlainText))
    Encode = ""
    For i = 1 To Len(Longkey)
        With Sheets("Sheet1").Application
            t = .Index(.Range("A2:Z27") _
                , .Match(Mid(PlainText, i, 1), .Range("A2:A27"), 0) _
                , .Match(Mid(Longkey, i, 1), .Range("A1:Z1"), 0))
        End With
        Encode = Encode & t
    Next i
    Decode = Application.Replace(Encode, InStr(tempText, " "), 0, "_")
    MsgBox Encode
    MsgBox Decode
End Sub

Re: อยากทราบวิธีตัดช่องว่างใน VBA

#22

by hydrotaxonomy » Mon Jul 23, 2012 3:21 am

1. หนูต้องการค่า decode กลับมาให้ได้ เหมือนค่า message ที่เราป้อนเข้าไปนะคะ

longkey = POPPOPP
Encode = IVTQSHI

ในที่นี้ จับคู่เทียบได้ PI | OV | PT | PQ| OS | PH | PI

จะได้ค่า decode = thebest
แล้วถ้าหนู ต้องการให้ ค่า decode = the best (เพิ่มช่องว่างเข้าไป) ต้องการให้ ค่า decode แสดงออกมาเหมือน ค่า message คะ


2. ถ้าหนูต้องการ ให้ ค่า encode มีช่องว่างเหมือนกับ message หนูต้อง mid อะไรคะ

โดย key = POP
message = the best
longkey = POPPOPP

ในที่นี้ จับคู่เทียบได้ Pt | Oh | Pe | _ช่องว่าง | Pb | Oe | Ps | Pt

จากตารางจะได้ IVT_QSHI คือจากเดิมใช้ PlainText เทียบ
แต่จะลองเปลี่ยนมาใช้ message เทียบกับ Longkey ดูนะคะ

ขอบคุณสำหรับคำแนะนำคะ
Attachments
vba7.jpg
vba7.jpg (87.28 KiB) Viewed 214 times

Re: อยากทราบวิธีตัดช่องว่างใน VBA

#21

by snasui » Sun Jul 22, 2012 10:35 pm

:D จาก
snasui wrote: :D ลองยกตัวอย่างการเปรียบเทียบ Encode (IVTQSHI) กับ Longkey (POPPOPP) เหมือนการอธิบายในความเห็นก่อนหน้ามาให้ดูหน่อยครับว่ามันได้ผลลัพธ์ตัวแปร Decode เป็นคำว่า the best ได้อย่างไร
ลองเปรียบเทียบแบบจับคู่ให้กลับมาเป็น the best เหมือนกับอธิบายแบบจับคู่ตามด้านล่างให้ดูอีกทีครับ จากภาพที่แนบมาล่าสุดยังมองไม่ออกว่าจะเป็น the best ได้อย่างไร เดิมเคยเปรียบเทียบไว้ตามด้านล่างครับ
hydrotaxonomy wrote:หนูต้องการเอา Longkey P

เทียบกับ Plaintext t

ในที่นี้ จับคู่เทียบได้ Pt | Oh | Pe | Pb | Oe | Ps | Pt

จากตารางจะได้ IVTQSHI

Re: อยากทราบวิธีตัดช่องว่างใน VBA

#20

by hydrotaxonomy » Sun Jul 22, 2012 6:39 pm

ตอนที่ decode มันต้องใช้ความยาวของ message ซึ่งมันมีช่องว่าง

คือหนูต้องการค่า decode กลับมาให้ได้ เหมือนค่า message ที่เราป้อนเข้าไปนะคะ
Attachments
vba6.jpg
vba6.jpg (55.63 KiB) Viewed 378 times

Re: อยากทราบวิธีตัดช่องว่างใน VBA

#19

by snasui » Sun Jul 22, 2012 6:18 pm

:D ลองยกตัวอย่างการเปรียบเทียบ Encode (IVTQSHI) กับ Longkey (POPPOPP) เหมือนการอธิบายในความเห็นก่อนหน้ามาให้ดูหน่อยครับว่ามันได้ผลลัพธ์ตัวแปร Decode เป็นคำว่า the best ได้อย่างไร

Re: อยากทราบวิธีตัดช่องว่างใน VBA

#18

by hydrotaxonomy » Sun Jul 22, 2012 5:50 pm

อาจารย์คะ ถ้าหนูจะแปลงค่า โดยเทียบ encode กับ longkey มาเทียบกันทีละตัว โดยใช้ความยาวของตัวแปร message ที่ยังไม่ได้ตัดช่องว่าง
ซึ่งมันจะไปเก็บค่าไว้ในตัวแปร decode

จากตัวอย่าง
message = the best
Longkey = POPPOPP
encode = IVTQSHI

จะได้ decode ออกมาเป็น the best

ซึ่งความยาว Longkey = 7
แต่ความยาว message = 8

แต่มัน debug คะ ช่วยแก้ไขด้วยนะคะ

Code: Select all

Public Sub Crypto01()
    Dim Key As String, Message As String, PlainText As String, Longkey As String, DecodeSpace As String, _
    Decode As String
    Dim i As Integer, p As Integer
    Key = InputBox("Enter the key of encryption")
    Key = UCase(Key)
    Message = InputBox("Enter the message that you want to send")
    PlainText = Replace(Message, " ", "")
    Longkey = Left(Application.WorksheetFunction.Rept(Key, 10), Len(PlainText))
    MsgBox "Key = " & Key
    MsgBox "PlainText = " & PlainText
    MsgBox "Longkey = " & Longkey
    For i = 1 To Len(Longkey)
        With Sheets("Sheet1")
            t = Application.Index(.Range("A2:Z27") _
                , Application.Match(Mid(PlainText, i, 1), .Range("A2:A27"), 0) _
                , Application.Match(Mid(Longkey, i, 1), .Range("A1:Z1"), 0))
        End With
        Encode = Encode & t
    Next i
    MsgBox Encode
    For p = 1 To Len(Message)
        With Sheets("Sheet1")
            If DecodeSpace = " " Then
                Decode = Decode + " "
                    i = i - 1
            Else
                i = Application.Index(.Range("B2:Z27") _
                    , Application.Match(Mid(Encode, i, 1), .Range("B2:Z27"), 0))
                    , Application.Match(Mid(Message, i, 1), .Range("A1:Z1"), 0))
               Decode = Decode & p
        End If
        End With
    Next p
    MsgBox Decode
   
End Sub

Re: อยากทราบวิธีตัดช่องว่างใน VBA

#17

by hydrotaxonomy » Sun Jul 22, 2012 3:53 pm

ขอบคุณสำหรับคำแนะนำคะ หนูขอเรียกว่าอาจารย์แล้วกันนะคะ ขอบคุณจริงๆ คะ อาจารย์ช่วยหนูได้มากเลยคะ

Re: อยากทราบวิธีตัดช่องว่างใน VBA

#16

by snasui » Sun Jul 22, 2012 3:26 pm

:D ลองดู Code ตามด้านล่างครับ

Code: Select all

Public Sub Crypto01()
    Dim Key As String, PlainText As String
    Dim Longkey As String, Encode As String
    Dim t As String, i As Integer
    Key = InputBox("Enter the key of encryption")
    Key = UCase(Key)
    PlainText = InputBox("Enter the message that you want to send")
    PlainText = Replace(PlainText, " ", "")
    Longkey = Left(Application.Rept(Key, 10), Len(PlainText))
    Encode = ""
    For i = 1 To Len(Longkey)
        With Sheets("Sheet1")
            t = Application.Index(.Range("A2:Z27") _
                , Application.Match(Mid(PlainText, i, 1), .Range("A2:A27"), 0) _
                , Application.Match(Mid(Longkey, i, 1), .Range("A1:Z1"), 0))
        End With
        Encode = Encode & t
    Next i
    MsgBox Encode
End Sub

Re: อยากทราบวิธีตัดช่องว่างใน VBA

#15

by hydrotaxonomy » Sun Jul 22, 2012 2:51 pm

สมมุติ key = pop
message = the best

จะได้ Plaintext = thebest
Longkey = POPPOPP

หนูต้องการเอา Longkey P

เทียบกับ Plaintext t

ในที่นี้ จับคู่เทียบได้ Pt | Oh | Pe | Pb | Oe | Ps | Pt

จากตารางจะได้ IVTQSHI

แล้วก็นำตัวอักษรที่เทียบจากตาราง มาเรียงเป็นคำใหม่ใช้ชื่อตัวแปรว่า encode แล้วแสดงผลคะ

แต่หนูไม่รู้ว่าจะ mid แล้ววน loop ยังไงนะคะ

รบกวนช่วยให้คำแนะนำด้วยคะ ขอบคุณคะ
Attachments
vba5.jpg
vba5.jpg (90.39 KiB) Viewed 396 times

Re: อยากทราบวิธีตัดช่องว่างใน VBA

#14

by snasui » Sun Jul 22, 2012 1:07 pm

:D Code ที่เขียนมาผมลองปรับเพื่อให้กระชับเป็นตามด้านล่าง

Code: Select all

Public Sub Crypto01()
    Dim Key As String, PlainText As String, Longkey As String
    Key = InputBox("Enter the key of encryption")
    Key = UCase(Key)
    PlainText = InputBox("Enter the message that you want to send")
    PlainText = Replace(PlainText, " ", "")
    Longkey = Left(Application.WorksheetFunction.Rept(Key, 10), Len(PlainText))
    MsgBox "Key = " & Key
    MsgBox "PlainText = " & PlainText
    MsgBox "Longkey = " & Longkey
End Sub
ส่วนที่อธิบายเพิ่มเติมมายังไม่เข้าใจ
hydrotaxonomy wrote:ดึงค่าจากตัวแปร long_key ทีละตัวมาตรวจว่าตรงกับใน column A แถวไหน แล้วให้ส่งค่าแถวกลับมาเก็บไว้
เก็บไว้ในตัวแปรใด :?:
hydrotaxonomy wrote:หลังจากนั้นทำการดึงค่าจากตัวแปร plaintext ทีละตัวมาตรวจว่าตรงกับ column ใด ใน R1
R1 คืออะไร :?:
hydrotaxonomy wrote:นำค่าตัวอักษรที่ได้ในแต่ละรอบมาเรียงต่อกัน ซึ่งจะได้คำใหม่ขึ้นมา
ช่วยยกตัวอย่างให้เป็นภาพด้วยครับ ยกตัวอย่างข้อความที่คีย์ และยกตัวอย่างคำตอบที่ถูกต้องว่าควรได้เป็นอย่างไร เพื่อจะได้เข้าใจตรงกัน สามารถทำลูกศรโยงไปโยงมา ใส่สี ตีเส้นได้เต็มที่ครับ

Re: อยากทราบวิธีตัดช่องว่างใน VBA

#13

by hydrotaxonomy » Sun Jul 22, 2012 10:11 am

ดึงค่าจากตัวแปร long_key ทีละตัวมาตรวจว่าตรงกับใน column A แถวไหน แล้วให้ส่งค่าแถวกลับมาเก็บไว้

หลังจากนั้นทำการดึงค่าจากตัวแปร plaintext ทีละตัวมาตรวจว่าตรงกับ column ใด ใน R1

นำค่าตัวอักษรที่ได้ในแต่ละรอบมาเรียงต่อกัน ซึ่งจะได้คำใหม่ขึ้นมา

หนูต้องการทำแบบนี้นะคะ แต่หนูเขียนต่อไม่ได้แล้ว เลยมาถามผู้รู้คะ

รบกวนช่วยให้คำแนะนำด้วยนะคะ ขอบคุณคะ

Re: อยากทราบวิธีตัดช่องว่างใน VBA

#12

by snasui » Sun Jul 22, 2012 7:17 am

:D ดึงค่า Key จากไหนมาทีละตัวครับ ลองอธิบายวิธีการเป็นขั้น ๆ มาตามลำดับ และจาก Code ที่แนบมา ติดปัญหาใดครับ

Top