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 4 years ago.
Improve this question
I'm trying to write a simple VB program to read the file names in a given directory. This is what I've written:
Imports System
Imports System.IO
Imports System.Text
Module Program
Sub Main(args As String())
Dim FolderPath As String = 'C:\Users\uarenet\Downloads\Projects\Mock_Tables\_ExcelTables'
Dim FileNames As String() = Directory.GetFiles(FolderPath)
For Each FileName As String In FileNames
Console.WriteLine(FileName)
Next
End Sub
End Module
For some reason Visual Studio is not recognizing the line Dim FileNames.... statement, and, because of this, refuses to process the For Each.... statement.
Thanks in advance for any help or suggestions you can offer.
You used this character ' to create a string although this character in Visual Basic language used for writing comments not string as you expected, string written in double quotes like "Hello world", so I suggest replacing your code with this:-
Sub Main(args As String())
Dim FolderPath = "C:\Users\uarenet\Downloads\Projects\Mock_Tables\_ExcelTables"
Dim FileNames = Directory.GetFiles(FolderPath)
For Each FileName As String In FileNames
Console.WriteLine(FileName)
Next
End Sub
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 last year.
Improve this question
I've got an application which is watching over executed processes on a device using a managementeventwatcher, like so...
Dim wmiq As String = "SELECT TargetInstance FROM __InstanceCreationEvent WITHIN .025 WHERE TargetInstance ISA 'Win32_Process' AND TargetInstance.Name like '%'"
Dim scope As String = "\\.\root\CIMV2"
startProcWatcher = New ManagementEventWatcher(scope, wmiq)
AddHandler startProcWatcher.EventArrived, AddressOf ProcessStarted
startProcWatcher.Start()
And my handler (just logging for now)...
Private Shared Sub ProcessStarted(sender As Object, e As EventArrivedEventArgs)
Dim targetinstance As ManagementBaseObject = e.NewEvent.Properties("TargetInstance").Value
Dim processname As String = targetinstance.Properties("Name").Value.ToString
Dim exepath As String = targetinstance.Properties("ExecutablePath").Value.ToString
Dim thisexeinfo As New FileInfo(exepath)
If Not ProcessExclusionList.Contains(processname) Then
MyApp.DoLogging("Process Started : " & processname & "(" & exepath & ")")
End If
End Sub
This works a treat and I successfully capture the event creation with minimal resource usage (as opposed to Process.GetProcesses(), which was hammering resource!), however I notice that if a second instance of the same process is run, I do not get an event on the second execution.
For example, I can run calculator and my watcher will log calc.exe was executed with all the associated properties. If I then open a second calculator my watcher sees nothing.
I'm guessing I need to modify the WMI query slightly, but my WMI is limited and I'm not struggling.
Can anyone help out with this?
TIA
The code I posted actually works perfectly for multiple instances of a process, however when I was testing, I used calc and it turns out calc spawns multiple instances of itself all under the same process.
repeating the test with any other executable/process results in the desired behavior.
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 4 years ago.
Improve this question
I want to open FrmNovaRegra with a button click in another form.
I already tried the basic "Dim form as new FrmNovaRegra" and "form.show()" it didnt work, how can i open it? The code of the Form that i want to open is in the next line:
Public Class FrmNovaRegra
Private regras As BServices.NovaRegra
'Private MyDictionary As New Dictionary(Of String, List(Of String))
Public Sub New(ByVal cls As BServices.NovaRegra)
InitializeComponent()
Me.regras = cls
End Sub
Your form needs it's parameter, because there are no other overloads. There are many ways you can correct this.
If you have the cls As BServices.NovaRegra you can create the form using:
Dim form as new FrmNovaRegra(cls)
If you want to create a new one on the fly, that's also possible:
Dim form as new FrmNovaRegra(New BServices.NovaRegra())
This new cls might need some parameters too, I'm not familiar with this class.
Another way to work around this would be to add a new overload which doesn't need a parameter, but your form looks like it needs the cls, so let me know if you need more explanations for this one as a comment.
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 8 years ago.
Improve this question
Alright, I've managed to get a string containing HTML content inside of it, but I need to get into an HTMLDocument for parsing.
I've tested the following code, and I've been unable to get it to work through any of the variations I've tried.
Dim webclient As New System.Net.WebClient
Dim result As String = webclient.DownloadString(link)
Dim htm As HtmlDocument
htm = htm.Write(result)
Dim sDD As Object
sDD = htm.GetElementById("tag-sidebar")
Dim IDD As Object
IDD = htm.GetElementById("highres")
Currently it is telling me that htm = htm.Write(result) does not produce a value, so I'm sort of stumped.
I'm Currently using Microsoft Visual Studio 2013 Professional
The error just indicates that the Write method does not produce a value. In VB-speak that means Write is a Sub, not a Function.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
Hi i really need some help with this, I need to make a multiple choice question program that reads the questions and answers from 2 different text files (notepad files)
but when I try I cant seem to get it working. i have tried loops but that didn't work then I tried arrays but that didn't meet the requirements of reading form a text file
So I come to you all I need help is with reading a text file line by tine and then updating it when a new question needs to be given
I cannot 1 read the line by line (questions.txt) and i need to have match the question which are in answers.txt then i need to update it when next question is clicked
VB.Net
Program i need to create must do the following
Questions and answers should be loaded from a file called questions.txt and answers.txt respectively
-Questions should also appear in random order, every time program is executed
-update form for next question
-keep track on how many questions are correct
Any resources or tutorials on any of the above would be muchly appreciated
Total edits: 198305769 lol. Cleaned up the answer, and this should get you nearly complete. Cheers.
Declare a global variable (integer); that's where you'll assign the amount of questions the user has answered:
Public Class Form1
Dim keepScore As Integer = 0
Not the neatest, but it appends each line from a selected text file into an array and then you can iterate through it.
Dim ofd As New OpenFileDialog
ofd.ShowDialog()
Dim xstr = ofd.FileName
Dim questions() As String = IO.File.ReadAllLines(ofd.FileName)
Dim answers() As String = IO.File.ReadAllLines(ofd.FileName)
Dim sw As New StringBuilder
Dim i As Integer = 0
Do Until i = questions.Count()
sw.AppendLine(Trim(questions(i)))
MsgBox(questions(i)) 'Only added this so you can see the lines
i = i + 1
Loop
Do Until i = answers.Count()
sw.AppendLine(Trim(answers(i)))
MsgBox(answers(i)) 'Only added this so you can see the lines
i = i + 1
Loop
Add onto the end of this function an if statement:
If CorrectAnswer.Checked = True 'Assuming you are using a RadioButton Group, or CheckBox
keepScore = keepScore + 1
End If
Here is a quick number randomiser, assuming you have 20 questions (change the 20 accordingly to whatever amount of questions you have):
Randomize()
Dim i As Integer = CInt(Int(20 * Rnd() + 1))
MsgBox(i)
Best of luck.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Using Visual Basic, I want to replace a text within a String with another String. I do not know the location of this text within the String. How can I accomplish this?
Thanks for any help.
Try:
X = X.Replace("original"," toReplace")
Or this link:
Imports System.Text.RegularExpressions
Module Module1
Sub Main()
' Input string.
Dim input As String = "Dot Net Not Perls"
' Use Regex.Replace with string arguments.
Dim output As String = Regex.Replace(input, "N.t", "NET")
' Print.
Console.WriteLine(input)
Console.WriteLine(output)
End Sub
End Module
Output
Dot Net Not Perls
Dot NET NET Perls
The replace method does not require you to know the location. You specify the original value, the string to look for, and the string to change it too. Very straight forward.
Dim aString As String = Replace("String to Search", "String to Find", "String to Replace With")