Jump to content

vb.net changes to AutoIt


 Share

Recommended Posts

Is it possible to do this simply vb.net program which finds words (or similar) in AutoIt? If is how (or can be someone so nice and shows code)?

Module Module1

Sub Main()

Console.Clear()

Console.Write("Write text: ")

Dim Text = Console.ReadLine()

If ContainsSuchword(Text) Then

Console.WriteLine("There is one or more such words")

Else

Console.WriteLine("There is no such words")

End If

Threading.Thread.Sleep(1000)

End Sub

Private Function ContainsSuchword(ByVal text As String) As Boolean

Dim Suchwords = New String() {"word1", "word2", "you were"}

For Each Suchword In Suchwords

If text.ToLower.Contains(Suchword) Then

Return True

End If

Next

Return False

End Function

End Module

Link to comment
Share on other sites

  • Moderators

Codemike,

Welcome to the AutoIt forum. :)

You obviously missed this at the top of the page. I have asked a Mod to move it - please do NOT start another thread in the meantime. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Here's a line by line conversion of your code. Your old code is put in comments behind the original lines. I have sometimes shortly highlighted the differences between AutoIt and VB.

Writing a console application is not as favorable in AutoIt as it is in VB. If you want to test a console application in AutoIt you have to compile it first. Therefore I have chosen to use InputBox and MsgBox. You are probably familiar with these: VB has them too.

[autoit]Main() ; Main needs to be called in AutoIt. Alternatively, you don't have to define a Main() at all

Func Main() ; Sub Main()

; Console.Clear()

$Text = InputBox("", "Enter text please") ; Console.Write("Write text: ")

; Dim Text = Console.ReadLine()

If ContainsSuchword($Text) Then ;If ContainsSuchword(Text) Then

MsgBox(0, "", "There is one or more such words") ;Console.WriteLine("There is one or more such words")

Else ; Else

MsgBox(0, "", "There is no such words") ; Console.WriteLine("There is no such words")

EndIF ; End If

Sleep(1000)

Link to comment
Share on other sites

Here's a line by line conversion of your code. Your old code is put in comments behind the original lines. I have sometimes shortly highlighted the differences between AutoIt and VB.

Writing a console application is not as favorable in AutoIt as it is in VB. If you want to test a console application in AutoIt you have to compile it first. Therefore I have chosen to use InputBox and MsgBox. You are probably familiar with these: VB has them too.

[autoit]Main() ; Main needs to be called in AutoIt. Alternatively, you don't have to define a Main() at all

Func Main() ; Sub Main()

; Console.Clear()

$Text = InputBox("", "Enter text please") ; Console.Write("Write text: ")

; Dim Text = Console.ReadLine()

If ContainsSuchword($Text) Then ;If ContainsSuchword(Text) Then

MsgBox(0, "", "There is one or more such words") ;Console.WriteLine("There is one or more such words")

Else ; Else

MsgBox(0, "", "There is no such words") ; Console.WriteLine("There is no such words")

EndIF ; End If

Sleep(1000)

Thanks very much your answer. But I'm a beginner in the programming. Can you (or some other) show working code? Don't I need this end to get my vb.net (which is not my original code) program to work?

End Sub

Private Function ContainsSuchword(ByVal text As String) As Boolean

Dim Suchwords = New String() {"word1", "word2", "you were"}

For Each Suchword In Suchwords

If text.ToLower.Contains(Suchword) Then

Return True

End If

Next

Return False

End Function

End Module

Link to comment
Share on other sites

Damnit. The forum was being broken for me yesterday in multiple places. I did translate that part and I saw the code was fully working after some testing, it just didn't came through in the post. Ofcourse I didn't keep a backup, so I have to re-do it.

Main() ; Main needs to be called in AutoIt. Alternatively, you don't have to define a Main() at all

Func Main() ; Sub Main()
    ; Console.Clear()
    $Text = InputBox("", "Enter text please") ; Console.Write("Write text: ")
    ; Dim Text = Console.ReadLine()
    If ContainsSuchword($Text) Then ;If ContainsSuchword(Text) Then
        MsgBox(0, "", "There is one or more such words") ;Console.WriteLine("There is one or more such words")
    Else ; Else
        MsgBox(0, "", "There is no such words") ; Console.WriteLine("There is no such words")
    EndIF ; End If
    
    Sleep(1000) ;Threading.Thread.Sleep(1000)
EndFunc; End Sub

Func ContainsSuchWord($Text) ;Private Function ContainsSuchword(ByVal text As String) As Boolean
    Dim $Suchwords[3] = ["word1", "word2", "you were"] ;Dim Suchwords = New String() {"word1", "word2", "you were"}
    For $i = 0 To UBound($Suchwords)-1 ;For Each Suchword In Suchwords
        If StringInStr($Text, $Suchwords[$i]) Then ;If text.ToLower.Contains(Suchword) Then
            Return True
        EndIf ;End If
    Next
    Return False
EndFunc;End Function

Here you go. :/

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...