Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
i want to read from exe files so i find this code
Dim strData As String
Dim lngFind As Long
Open txtAdrsOfFile For Binary As #1
strData = Space$(FileLen(txtAdrsOfFile))
Get #1, , strData
Close #1
lngFind = InStr(1, strData, txtFindString)
If strData = txtFindString Then
MsgBox "FIND"
Else
MsgBox "NOT FIND"
End If
its need a command buttton and 2 text boxs
but its not working
if there be a way to use that code if you guys can plz help me with doing this for multitipe strings i mean we can read more than 1 form a file
tnx
Firstly instr() returns an integer of the position of the find string inside the search string
It will not alter the two strings you pass it.
So instead of checking
If strData = txtFindString Then
You should check
If lngFind > 0 then
MsgBox "FIND"
Else
MsgBox "NOT FIND"
End If
This is because StrData is still going to equal what the contents of your file was before you call instr()
Also as pointed out if you searching for text and aren't worried about matching case you should call instr() with the text flag
lngFind = InStr(1, strData, txtFindString,1)
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
im new to vbs-,Powershell-, ... coding
i need to build something that checks for new files in a specific directory and opens all newly added files automatically.
i've found this post which seems to fit my needs perfectly: https://devblogs.microsoft.com/scripting/how-can-i-automatically-open-new-files-added-to-a-folder/
I tweaked the code to my situation like this:
Set objShell = CreateObject(“Wscript.Shell”)
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2”)
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
(“SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE ” _
& “Targetinstance ISA ‘CIM_DirectoryContainsFile’ and ” _
& “TargetInstance.GroupComponent= ” _
& “‘Win32_Directory.Name=””T:\\\\Reporting\\\\AutoOpen””‘”)
Do
Set objLatestEvent = colMonitoredEvents.NextEvent
strNewFile = objLatestEvent.TargetInstance.PartComponent
arrNewFile = Split(strNewFile, “=”)
strFileName = arrNewFile(1)
strFileName = Replace(strFileName, “\\”, “\”)
strFileName = Replace(strFileName, Chr(34), “”)
objShell.Run(“excel.exe ” & strFileName)
Loop
Bummer that the above post contains no details on how to actually use the code or what programming language it is :D
I assumed this snipped is for vbscript. When i put it in a .vbs file and execute it, i get the error-message "invalid character, line 1, character 29, compiling error, ..." -> this character is the first quotation mark in line 1.
So i also tried powershell, but it seems like the code doesnt fit there either.
... So what kind of code is this after all?
And how can i put it in an executable file?
Thank you so much in advance.
The slanted or smart quotes “.” you are using are invalid in vbscript code.
You should replace all of them with regular double quotes "
Applications such as MS Word tend to convert regular quotes with these slanted ones, so that might be where you got them from.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I know that pause/play key(from keyboard)'s keyCode is 179, but how can I programically press those multimedia keys from VB6? There are some questions about it but they're for C#/C++/VB.Net
You can use the Chr function to convert your keycode to a string that SendKeys can use:
SendKeys Chr(179)
You might run into a Permission Denied error next, which you can work around by using a WScript.Shell object by using this subroutine:
Private Sub SendKeysViaWshShell(p_iKeyCode As Integer, Optional p_fWait As Boolean = False)
Dim objWshShell As Object
Set objWshShell = CreateObject("WScript.Shell")
objWshShell.SendKeys Chr(p_iKeyCode), p_fWait
Set objWshShell = Nothing
End Sub
First off I'm sorry that i'm very very new to VBS, but i'm trying to create a little script that will complete a series of key strokes then on a website for work then go to another website and complete another series of key strokes.
Whilst on the first website there I need to ask a question like did the action complete. Yes or No.
If No then the script needs to go back to the start of the script. If yes then the script needs to continue.
Later on, on the second website after a few keystrokes I need to ask another question weather to loop the whole process or to stop.
I've googled a few message box solutions but it doesn't seem to work. I have
The first question box.
intSerialNumber = _
Msgbox("Was there a problem?", _
vbYesNo, "Problem?")
If intSerialNumber = vbYes Then
LoopShip
Else
Continue
End If
Continue
The Second question box.
If msgbox("Continue?", vbYesNo) = vbNo Then
WScript.quit
End If
if LoopShip = True Then
LoopShip
End If
Wend
Try using nested loops with functions for readability like this. The user can rerun the code from the first website as many times as they want and can rerun the code from both websites as many times as they want.
Dim problemsOccurred
problemsOccurred = vbYes
Do
Call firstWebsite()
problemsOccurred = secondWebsite()
Loop Until (problemsOccurred = vbNo)
Sub firstWebsite()
Dim firstWebsiteProblem
firstWebsiteProblem = vbYes
Do
'First Website code Goes here
firstWebsiteProblem = Msgbox("Was there a problem?", vbYesNo, "Problem?")
Loop Until (firstWebsiteProblem = vbNo)
End Sub
Function secondWebsite()
'Second WebSite code goes here
secondWebsite = MsgBox("Continue Whole Process?", vbYesNo)
End Function
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have list of strings. I am trying to append those string values to a text file.
Here is my code:
java_location = "#{second}#{first}"
The output of java_location is:
1.6.0_43/opt/oracle/agent12c/core/12.1.0.4.0/jdk/bin/java
1.6.0_43/opt/oracle/agent12c/core/12.1.0.4.0/jdk/jre/bin/java
1.5.0/opt/itm/v6.2.2/JRE/lx8266/bin/java
1.6.0_35/u01/app/oracle/product/Middleware/Oracle_BI1/jdk/jre/bin/java
I want this output writing into a text file.
How can i do that?
File.write('file.txt', java_location)
You want to open the file in append mode ('a') rather than readwrite ('w+') which truncates the existing file to zero length before writing
http://alvinalexander.com/blog/post/ruby/example-how-append-text-to-file-ruby
if first && second
java_location = "#{second}#{first}"
a << java_location
File.open("/home/weblogic/javafoundmodified.txt", 'a') do |file|
a.each {
|item|
file.puts item
}
end
end
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
The picture will make it all make sense. But I'm just trying to copy the text from below the "Author information:" Cell to another cell location. This isn't difficult for a few because it's just a simple copy and paste but I need to search the entire worksheet and extract all of the info from the first cell below "Author information:" At this point there are thousands of entries...
Screenshot Dropbox link: https://www.dropbox.com/s/nbyg8lkay3c5c9s/Screenshot%202013-12-27%2016.32.38.png
Any help would be fantastic!
For ease, try the following.
In cell C2 type this formula =IF(A1="Author Information:",A2,"")
Copy this formula all the way down
copy the results in column C to another sheet and paste-special with values only
Sort that sheet to get rid of blanks
That should be a quick and dirty way to get it done.
Try this code:
Sub copyAuthorInfo()
Dim src As Worksheet, tgt As Worksheet
Dim irows As Long
Dim rrows As Long
Set src = ThisWorkbook.Sheets("Sheet1") ' this is the sheet with the original data
Set tgt = ThisWorkbook.Sheets("Sheet2") ' author info will be copied into this sheet
irows = src.UsedRange.Rows.Count ' count the number of used rows in sheet 1
rrows = 1 'row counter for the target sheet
For i = 1 To irows
If Cells(i, 1).Value = "Author information:" Then 'make sure to adjust the search text
' copying columns A to C. Change the 3 in the following line to copy more columns.
Range(Cells(i + 1, 1), Cells(i + 1, 3)).Copy tgt.Range("A" & rrows)
rrows = rrows + 1
End If
Next
End Sub
To run the code, you need to open the Visual Basic Editor (VBE) with Alt-F11 or your preferred method. Use Insert > Module and paste the code. You can run the code by hitting F5 while the cursor is somewhere in the code.
You have tagged with OSX. Does that mean you use a Mac? You also tagged with Excel 2007 and 2010. The code will run fine in these, but not in Excel 2008 for Mac, because it does not support VBA.