Jump to content

Search for a letter


Bea
 Share

Recommended Posts

Hey i am trying to make a gui with a button formation button and than a msg box show if there were any errors and how often the script ist startet by reading a text file

my problem is that i dont get it that the script scans for specific letters :S for example count only the "E" in the file

 

the Goal is that the Script counts the "E" "B" and "S" in the text file but right now it only counts ever letter :S somone know how to fix it, pls help a girl :(

$file = FileOpen("logs.txt", 0)
$charcount = -1

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

Do
    $chars = FileRead($file, 1)
    $charcount += 1
Until @error = -1


MsgBox(4096, "Info", "Bilder  geändert:   "& $charcount _
         & @CRLF & "Status geändert:   " & $charcount _
         & @CRLF & "FEHLER: " & $charcount )



FileClose($file)
Exit

 

Link to comment
Share on other sites

Basically like this (untested).

Local $iSCount, $iBCount, $iECount
Local $sFileName = @ScriptDir & "\Logs.txt"
    If FileExists($sFileName) = 0 Then Exit MsgBox(4096, "Error", $sFileName & " could not be found.")
Local $sFileText = FileRead('logs.txt')
StringReplace($sFileText, 's', 's')
    $iSCount = @extended

StringReplace($sFileText, 'b', 'b')
    $iBCount = @extended

StringReplace($sFileText, 'e', 'e')
    $iECount = @extended

MsgBox(4096, "Info", "Bilder  geändert:   "& $iBCount _
         & @CRLF & "Status geändert:   " & $iSCount _
         & @CRLF & "FEHLER: " & $iECount)

 

Link to comment
Share on other sites

do you need to count them all independently or just how many total?

$str = "Test with 10 characters are either 'e' 's' or 'b'."

msgbox(0, '' , ubound(StringRegExp($str , "e|s|b" , 3)))

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

7 hours ago, iamtheky said:

do you need to count them all independently or just how many total?

$str = "Test with 10 characters are either 'e' 's' or 'b'."

msgbox(0, '' , ubound(StringRegExp($str , "e|s|b" , 3)))

 

I need them to count them all independet for example if in the text file there is written  "bbsssfff"  2xb , 3xS, 3xF the rest works but by this purt i got stucked :S

Link to comment
Share on other sites

Try this:

#include <MsgBoxConstants.au3>
#include <FileConstants.au3>


$sFilePath = @ScriptDir & "\log.txt"

$hFileOpen = FileOpen($sFilePath, $FO_READ)

If $hFileOpen = -1 Or Not FileExists($sFilePath) Then
    MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.")
    Exit
EndIf

$sFileRead = FileRead($hFileOpen)

FileClose($hFileOpen)


StringReplace($sFileRead, "s", "s")
$i_S_Count = @extended

StringReplace($sFileRead, "b", "b")
$i_B_Count = @extended

StringReplace($sFileRead, "e", "e")
$i_E_Count = @extended

MsgBox($MB_ICONINFORMATION, "Info", "S occurrence: " & $i_S_Count & @CRLF & "B occurrence: " & $i_B_Count & @CRLF & "E occurrence: " & $i_E_Count)

 

My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Link to comment
Share on other sites

1 hour ago, Nessie said:

Try this:

#include <MsgBoxConstants.au3>
#include <FileConstants.au3>


$sFilePath = @ScriptDir & "\log.txt"

$hFileOpen = FileOpen($sFilePath, $FO_READ)

If $hFileOpen = -1 Or Not FileExists($sFilePath) Then
    MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.")
    Exit
EndIf

$sFileRead = FileRead($hFileOpen)

FileClose($hFileOpen)


StringReplace($sFileRead, "s", "s")
$i_S_Count = @extended

StringReplace($sFileRead, "b", "b")
$i_B_Count = @extended

StringReplace($sFileRead, "e", "e")
$i_E_Count = @extended

MsgBox($MB_ICONINFORMATION, "Info", "S occurrence: " & $i_S_Count & @CRLF & "B occurrence: " & $i_B_Count & @CRLF & "E occurrence: " & $i_E_Count)

Man this worked Great, thank you so mouch i only have one question is it possible to color the numbers  for example "E occurrence:  4" if that would be possible it would be great

 

Link to comment
Share on other sites

It is not possible with the standard MsgBox function. Also you can see that udf. Or just simply make a GUI ;)

My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

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...