I currently use iMacro for Firefox for quick form filling with random letters.
SET !VAR1 EVAL("var letters = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','w','x','y','z']; var string = ''; for(var i = 0; i < 11; i++){string += letters[parseInt(Math.random() * 25)]}; string")
EVENT TYPE=CLICK SELECTOR="#namex" BUTTON=0
EVENTS TYPE=KEYPRESS SELECTOR="#namex" CHARS="{{!var1}}"
Result is e.g. adionudmeai.
I have a text file that containing
one hundred thousand names in this format.
johny.hunter
tim.davies
emil.bernadette
I want to use this names instead of the random combinations
with two additional random numbers at the end.
The end result should look like bill.cayne32.
Here is the code for random names with two additional random numbers at the end:
SET !DATASOURCE names.txt
SET linesInTxt 100000
SET rndLine EVAL("Math.floor(Math.random()*'{{linesInTxt}}') + 1;")
SET !DATASOURCE_LINE {{rndLine}}
SET !VAR1 EVAL("'{{!COL1}}' + Math.random().toString().substr(2, 2);")
I Use pre-generated strings from a text/csv file (Can be generated manually or by a 'random name generator' online).
Generate a file.csv where each line holds comma seperated info for one user. Info is accessed as {{!COL1}} for first item, 2 for second item etc'.
Using this csv method allows you to split first/last names and use them for both info filling and for the desired username with a period in between.
SET !DATASOURCE C:\Temp\stackoverflow.csv
SET !LOOP 1337 'where to start in the csv file
SET !DATASOURCE_LINE {{!LOOP}}
EVENTS TYPE=KEYPRESS SELECTOR="#new_post>DIV>P>DIV>DIV" CHARS={{!COL1}}{{!COL2}}.{{!COL3}}{{!VAR1}}
stackoverflow.csv file example:
pika,chuu,easypassword123
wobbu,ffet,mypassword
chari,zard,123456
after {{!COL1}} you can insert your random {{!VAR1}} or just {{!LOOP}} if it doesn't have to be real random.
To get VAR1 to display numbers and not chars do:
SET !VAR1 EVAL("var letters = ['1','2','3','4','5','6','7','8','9','0']; var string = ''; for(var i = 0; i < 2; i++){string += letters[parseInt(Math.random() * 10)]}; string")
Related
I have a simple table that has a column with a date in this format:
MM/DD/YYYY.
Unfortunately, there are some folks who are working without leading zeros.
Therefore I would like to add a leading zero into the Month and Day element using Power Query to have a common format.
But how? Does someone have any function to share?
Again, not sure why you want to do this, but
Assuming all of the entries are text that looks like dates, you can use the following M-Code:
Split the string on the delimiter
Change each entry in the list to a number
Add 2000 to the last number
Change the numbers back to text with a "00" format
Recombine with the delimiter
let
Source = Excel.CurrentWorkbook(){[Name="Table29"]}[Content],
//set type = Text
#"Changed Type" = Table.TransformColumnTypes(Source,{{"TextDate", type text}}),
xform = Table.TransformColumns(#"Changed Type",
{"TextDate", each
let
x = Text.Split(_,"/"),
y = List.Transform(x,each Number.From(_)),
z = List.ReplaceRange(y,2,1, {2000+y{2}}),
a= List.Transform(z,each Number.ToText(_,"00")),
b = Text.Combine(a,"/")
in b})
in
xform
I am thinking a better solution might be to set up your data entry method so that all dates are entered as dates rather than text
Dim LineNo as Integer
LineNo = CStr(channel) 'This can have a value of 1 to 100
If LineNo = 1 then
Text1.Text = "Line one selected"
Elseif LineNo = 2 then
Text2.Text = "Line one selected"
'Etc etc
End if
I need to replace the number "1" in Text1.Text and every other TextBox with the value of LineNo? For example:
Text{LineNo}.Text
So I would not have to do a repeated "If" and have a smaller one line code like this:
Text{LineNo}.Text = "Line " & LineNo & " selected"
How would I do this?
Look into a Control array of text boxes. You could have txtLine(), for example, indexed by the channel number.
LineNo = CStr(channel)
txtLine(channel).Text = "Line " & LineNo & " selected"
To create the array, set the Index property of each of the text boxes to an increasing integer, starting at 0.
If you have a finite and relatively small number, you can use a property. I've used this approach with up to 30+ elements in a pinch. Super simple, easy pattern to recognize and replicate in other places. A bit if a pain if the number of elements changes in the future, but extensible nevertheless.
It uses the Choose statement, which takes an index N and returns the Nth element (1-based), hence, the check makes sure that N is > 0 and <= MAX (which you would configure).
Public Property Get TextBox txt(ByVal N As Long)
Const MAX As Long = 10
If N <= 0 || N > MAX Then Exit Property ' Will return a "Nothing". You could return the bound element if you prefer
set txt = Choose(Text1, Text2, Text3, Text4, Text5, Text6, Text7, Text8, Text9, Text10)
End Property
Then, you can simply reference them with the Property, much like an alias:
txt(1).Text = "Line 1 text"
txt(2).Text = "Line 2 text"
If you have an arbitrary number, then you are likely using a control array already, which is simpler because it can be referenced by Index already, so you can directly reference it.
If neither of these work for you and you have a very large number of controls, you can scan the Controls collection in a similar Property, attempting to match ctrl.Name with the pattern of your choice (e.g., matching the first 4 characters to the string "Text", thus matching Text1, Text2, etc, for an unlimited number). Theoretically, this should be future-proofed, but that's just theoretical, because anything can happen. What it does do for you is to encapsulate the lookup in a way that "pretends" to be a control array. Same syntax, just you control the value.
Public Property Get TextBox txt(ByVal N As Long)
Dim I As Long
For I = 0 To Controls.Count - 1 ' Controls is zero-based
' Perform whatever check you need to. Obviously, if you have a "Label" named
' "Text38", the assignment will throw an error (`TextBox = Label` doesn't work).
If Left(Controls(I).Name, 4) = "Text" Then
set txt = Controls(I)
End If
Next
' If you want the Property to never return null, you could uncomment the following line (preventing dereference errors if you insist on the `.Text` for setting/getting the value):
' If txt Is Nothing Then Set txt = Text1
End Property
Use the same way as above: txt(n).Text = "..."
I am stuck trying to figure out how to read the strings from a textgrid which is open in the window but not saved to the hard disk as a raw text file. My goal is to manipulate the strings and save them later.
I want to do something like this but don't really understand how the syntax would work.
tG$ = selectObject: selected$("TextGrid")
stringID = Read Strings from tG
numberOfStrings = Get number of strings
for stringNumber from 0 to numberOfStrings
selectObject: stringID
line$ = Get string: stringNumber
...
You need to loop through the intervals in the TextGrid and use appendFileLine to output the labels to a text file. For example:
# Your need to select the TextGrid manually, and it has only one tier (tier number 1)
outputFile$ = "~/Desktop/output.txt"
writeFile: outputFile$, "" ; start from an empty .txt
numberOfIntervals = Get number of intervals: 1 ; (this is tier 1)
for interval to numberOfIntervals
label$ = Get label of interval: 1, interval
if label$ != "" ; (we just want non-empty intervals)
xmin = Get start time of interval: 1, interval
xmax = Get end time of interval: 1, interval
appendFileLine: outputFile$, "'label$''tab$''xmin''tab$''xmax'"
endif
endfor
This script will output a .txt file with tab delimited values: label, xmin, xmax. You can change the appendFileLine arguments to your needs (tab$ is a predefined variable, which is... a tab).
TextGrid labels are not directly translatable to a Strings object because, unlike a TextGrid, Strings objects do not have tiers. So you could have code that takes all of the labels of a specific tier in a TextGrid and pushes them into a Strings object.
0. Creating an empty Strings
The problem here is that Praat does not want you to populate Strings object yourself, so there is no Create empty Strings.... However, you can subvert one of the existing commands to do this:
Create Strings as tokens: ""
1. Pushing the labels to a Strings object
Now that we have an empty Strings to populate, we can get to work:
procedure labelsToStrings: .tier
.textgrid = selected("TextGrid")
# Make sure this works with interval and point tiers
.item$ = if do("Is interval tier...", .tier) then
... "interval" else "point" fi
# Make the empty Strings
.strings = Create Strings as tokens: ""
Rename: selected$("TextGrid")
# Fetch each label, and insert it to the Strings object
selectObject: .textgrid
.n = do("Get number of " + .item$ + "s...", .tier)
for .i to .n
selectObject: .textgrid
.label$ = do$("Get label of " + .item$ + "...", .tier, .i)
# I assume you don't care about empty labels?
if .label$ != ""
selectObject: .strings
Insert string: 0, .label$
endif
endfor
# Make sure the new object is selected
selectObject: .strings
endproc
2. Profit!
You can try it out:
synth = Create SpeechSynthesizer: "English", "default"
To Sound: "This is some text.", "yes"
sound = selected("Sound")
textgrid = selected("TextGrid")
selectObject: textgrid
#labelsToStrings: 4
removeObject: sound, synth
View & Edit
3. Bonus
If you are interested in getting all the labels in a more manageable package, you might also be interested in the Index specified labels... command from the tgutils plugin, which I also wrote. (I know: I'm amazing at naming things).
That one does something similar to this, but instead of using a Strings object, it dumps all the labels to a Table, as well as the timestamp of points, or the start and end of intervals. And you can also specify subsets of labels to consider using a literal match or a regular expression.
With it, you can re-write #labelsToStrings to look like this:
procedure labelsToStrings: .tier
.name$ = selected$("TextGrid")
runScript: preferencesDirectory$ + "/plugin_tgutils/scripts/" +
... "index_specified_labels.praat", .tier, ".+", "yes"
.table = selected("Table")
Create Strings as tokens: ""
Rename: .name$
for .i to Object_'.table'.nrow
.label$ = Object_'.table'$[.i, "label"]
Insert string: 0, .label$
endfor
removeObject: .table
endproc
I could use some help in troubleshooting my code, which should run a report based on files in a folder, which meet certain criteria, read specific lines from those files and sum all the read values. And do some math later on.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
relativePath = wshShell.CurrentDirectory
Set ReportPath = objFSO.GetFolder(relativePath & "\KPI_STATS\")
count = 0
Now I'd like to check each file's filename in ReportPath if it matches current month...
For Each file In ReportPath.files
If instr(LCase(file.name), LCase(Right("0" & DatePart("m",Now),2))) > 0 Then
for i=0 to n
SIDENOTE: Now I don't understand why if I run msgbox(file) for testing only it gives me whole path to the folder with filename instead of filename only.
(let's continue)...and when it does, it should read only 14th line of text (last line and there are only numbers in it) of each file and store it in variable. I use Split for reading certain lines from files and arrays to hold read values but I can use as well something like sum = sum + sum(n-1).
a = Split(objFSO.OpenTextFile(file, ForReading).ReadAll, vbCrLf)
For j = 14
If UBound(a) = j Then
And now I'd like to write those values to separate Arrays
ar(i) = Array(a(j))
End If
Next
next
count = count + 1
End If
Next
I think I will manage to add and divide all the values as soon as I have all arrays in place but there i a problem. It doesn't work :'(
Thanks a lot.
I have an input box that I use to enter a alphanumeric account numbers in a database. The box accepts up to 25 characters. However, for data entry, each account number may not be as long as 25 characters. In such a case, the account numbers are saved with blank spaces before it instead of being saved to the left of the column. How can I solve this?
I would like each number to be saved like the two hyphenated numbers and not with a space like the first record.
Code summary:
Set objDB = New db.Detail_Data
objDB.ConnectionString = CONNECTSTRING
With objDB
.summary_code = CDbl(mvarSumcode)
.charge_code = UCase$(Me.txtChargeCode)
.clientID = UCase$(Me.txtClientID)
.JobID = UCase$(Me.txtJobID)
.Invno = UCase$(Me.txtInvno.Text)
.TransAmt = CCur(Me.txtTransAmt)
.Gl_accno = Format(Me.txtGL, "#########################")
.Description = Me.txtDescription
blnStatus = .AddDetail
End With
Looks like it works as coded. Your line:
.Gl_accno = Format(Me.txtGL, "#########################")
Format with the # symbol right justifies the string, filling in spaces on the left. Unless you add a ! like so (source).
.Gl_accno = Format(Me.txtGL, "!#########################")