|
You need a space before the And :
Me.TblPCRBindingSource.Filter = "ModelYear = " & (myear) & " And Line = " & CInt(txtLine.Text)
Otherwise, your filter will end up as:
ModelYear = 2017And Line = 42
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
modified 27-Jan-17 13:36pm.
|
|
|
|
|
This:
me.TblPCRBindingSource.Filter = "Line = " & CInt(txtLine.Text) And " ModelYear = " & (myear) gives me everything.
and this:
e.TblPCRBindingSource.Filter = "Line = " & CInt(txtLine.Text) " And ModelYear = " & (myear) gives me and end of statement error at the And ModelYear. It wants it like the first example - yet the first example isn't working.
this is coded in VB 2015
|
|
|
|
|
The first one is completely wrong.
- If you compile with
Option Strict On , you'll get a compiler error - BC30512 Option Strict On disallows implicit conversions from 'String' to 'Long'. - If you compile with
Option Strict Off , you'll get a runtime error - Conversion from string "line = 42" to type 'Long' is not valid.
The second one is missing the & between CInt(...) and " And ..." :
e.TblPCRBindingSource.Filter = "Line = " & CInt(txtLine.Text) & " And ModelYear = " & (myear)
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I am attempting to build a command line tool that will create shortcuts for an application on the start menu and desktop. I have existing code that I use elsewhere to create the shortcuts. However, the program looks at two different files one file has only the site code and the other has the other information needed to created the shortcut by site for a whole region. The idea is to go through both lines until it finds the 3 letter abbreviation for the site in both files. For example one file only contains BEC (sites2.txt - the city) and the other file (R03Sites2.csv - Region) contains 50 lines with a different cities and all the pertinent information.
Sub Main()
Dim strSiteCode
Dim strVistaFQDN
Dim strPort
Dim arrStr
Using sr As New StreamReader("c:\dell\R03Sites2.csv")
Dim line As String
Do
line = sr.ReadLine()
Dim Sites As String = My.Computer.FileSystem.ReadAllText("c:\dell\Sites2.txt")
If Not (line Is Nothing) Then
Console.WriteLine("Start processing loop")
arrStr = Split(sr.ReadLine, ",")
strSiteCode = arrStr(0)
strVistaFQDN = arrStr(1)
strPort = arrStr(2)
Console.WriteLine("Array populated... Enter if then statement")
If Trim(Sites) = Trim(strSiteCode) Then
Console.WriteLine(Trim(Sites) & " , " & Trim(strSiteCode))
Console.WriteLine("s=" & strVistaFQDN & " p=" & strPort)
Console.WriteLine("Successfully processed!")
Exit Do
Else
Console.WriteLine("Error: No Matching Information in the Sitecode and R03sites files!")
End If
End If
Loop Until line Is Nothing
End Using
End Sub
Here is the output:
\Dell>bcmass
Start processing loop
Array populated... Enter if then statement
Error: No Matching Information in the Sitecode and R03sites files!
Start processing loop
Array populated... Enter if then statement
Error: No Matching Information in the Sitecode and R03sites files!
Start processing loop
Array populated... Enter if then statement
Error: No Matching Information in the Sitecode and R03sites files!
Start processing loop
Array populated... Enter if then statement
Error: No Matching Information in the Sitecode and R03sites files!
Start processing loop
Array populated... Enter if then statement
Error: No Matching Information in the Sitecode and R03sites files!
Start processing loop
Array populated... Enter if then statement
Error: No Matching Information in the Sitecode and R03sites files!
Start processing loop
Array populated... Enter if then statement
Error: No Matching Information in the Sitecode and R03sites files!
Start processing loop
Array populated... Enter if then statement
Error: No Matching Information in the Sitecode and R03sites files!
Start processing loop
Array populated... Enter if then statement
Error: No Matching Information in the Sitecode and R03sites files!
Start processing loop
Array populated... Enter if then statement
Error: No Matching Information in the Sitecode and R03sites files!
Start processing loop
Array populated... Enter if then statement
Error: No Matching Information in the Sitecode and R03sites files!
Start processing loop
Array populated... Enter if then statement
Error: No Matching Information in the Sitecode and R03sites files!
Start processing loop
Array populated... Enter if then statement
Error: No Matching Information in the Sitecode and R03sites files!
Start processing loop
Array populated... Enter if then statement
Error: No Matching Information in the Sitecode and R03sites files!
Start processing loop
Array populated... Enter if then statement
Error: No Matching Information in the Sitecode and R03sites files!
Start processing loop
Array populated... Enter if then statement
Error: No Matching Information in the Sitecode and R03sites files!
Start processing loop
Array populated... Enter if then statement
Error: No Matching Information in the Sitecode and R03sites files!
Start processing loop
Array populated... Enter if then statement
Error: No Matching Information in the Sitecode and R03sites files!
Start processing loop
Array populated... Enter if then statement
Error: No Matching Information in the Sitecode and R03sites files!
Start processing loop
Array populated... Enter if then statement
Error: No Matching Information in the Sitecode and R03sites files!
Start processing loop
Unhandled Exception: System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.Array.InternalGetReference(Void* elemRef, Int32 rank, Int32* pIndices)
at System.Array.GetValue(Int32 index)
at Microsoft.VisualBasic.CompilerServices.Symbols.Container.GetArrayValue(Object[] Indices)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.InternalLateIndexGet(Object Instance, Object[] Arguments, String[] Argument
Names, Boolean ReportErrors, ResolutionFailure& Failure, Boolean[] CopyBack)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.ObjectLateInvokeDefault(Object Instance, Object[] Arguments, String[] Argum
entNames, Boolean ReportErrors, Boolean[] CopyBack)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateIndexGet(Object Instance, Object[] Arguments, String[] ArgumentNames)
at BCMASS.Module1.Main()
|
|
|
|
|
You're getting the exception because you've read a line from the file which doesn't contain two commas.
That's probably caused by the fact that you're skipping every other line:
line = sr.ReadLine()
If Not (line Is Nothing) Then
arrStr = Split(sr.ReadLine, ",")
You need to change that to re-use the line you've already read. You also need to check that the array returned from Split contains enough elements:
line = sr.ReadLine()
If line IsNot Nothing Then
arrStr = Split(line, ",")
If arrStr.Length >= 3 Then
strSiteCode = arrStr(0)
strVistaFQDN = arrStr(1)
strPort = arrStr(2)
...
You should also move the code that reads the contents of Sites2.txt outside of the loop. As it stands, you're reading the entire file for every line in Sites2.csv , even though you're not changing it.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks for the response. I made the suggested changes and am still having issues. This is what I have now:
Sub Main()
Dim strSiteCode
Dim strVistaFQDN
Dim strPort
Dim arrStr
Dim Sites As String = My.Computer.FileSystem.ReadAllText("c:\dell\Sites2.txt")
Using sr As New StreamReader("c:\dell\R03Sites3.csv")
Dim line As String
Do
line = sr.ReadLine()
Console.WriteLine("line = " & line)
Console.WriteLine("Start processing loop")
If line IsNot Nothing Then
arrStr = Split(line, ",")
If arrStr.Length >= 3 Then
strSiteCode = arrStr(0)
strVistaFQDN = arrStr(1)
strPort = arrStr(2)
Console.WriteLine(Trim(Sites) & " , " & Trim(strSiteCode))
Console.WriteLine("s=" & strVistaFQDN & " p=" & strPort)
Console.WriteLine("Array populated... Enter if then statement")
If Trim(Sites) = Trim(strSiteCode) Then
Console.WriteLine("Successfully processed!")
Exit Do
Else
Console.WriteLine("Error: No Matching Information in the Sitecode and R03sites files!")
End If
End If
End If
Loop Until line Is Nothing
End Using
End Sub
Here is the output (I cut the R03 file down to 2 entries):
C:\Dell>bcmass
line = BEC,test.beckley.com,19233
Start processing loop
BEC,BEC
, BEC
s=test.beckley.com p=19233
Array populated... Enter if then statement
Error: No Matching Information in the Sitecode and R03sites files!
line = BIR,test.birmingham.com,19230
Start processing loop
BEC,BEC
, BIR
s=test.birmingham.com p=19230
Array populated... Enter if then statement
Error: No Matching Information in the Sitecode and R03sites files!
line =
Start processing loop
The bold entries should read BEC,BEC and BEC,BIR instead of BEC,BEC,BEC and BEC,BEC,BIR. I'm not sure how make the if then statement read only the first BEC for the Sites2.txt file and the Site code out of R03sites3.csv and then continue processing/reading the matching information.
|
|
|
|
|
The reason you are getting the extra data in the output is because of the line:
Console.WriteLine(Trim(Sites) & " , " & Trim(strSiteCode))
You need to split the Sites data the same as the other lines, so you can compare BEC to BEC. Also, you only read the Sites data once, so how do you expect it to be different on subsequent passes through the loop?
|
|
|
|
|
Thanks for the response. You're suggestion helped but the if then statement still doesn't work. Also, Sites data never changes each computer at each site has a Sites data file with the appropriate entry. It only has one line in the file and it is formatted like this: BEC,BEC. Here is the new code:
Do
line = sr.ReadLine()
Console.WriteLine("line = " & line)
Console.WriteLine("Start processing loop")
If line IsNot Nothing Then
arrStr = Split(line, ",")
siteArr = Split(Sites, ",")
Site1 = siteArr(0)
If arrStr.Length >= 3 Then
strSiteCode = arrStr(0)
strVistaFQDN = arrStr(1)
strPort = arrStr(2)
Console.WriteLine(Trim(Site1) & " , " & Trim(strSiteCode))
Console.WriteLine("s=" & strVistaFQDN & " p=" & strPort)
Console.WriteLine("Array populated... Enter if then statement")
If Trim(Sites) = Trim(strSiteCode) Then
Console.WriteLine("Successfully processed!")
Exit Do
Else
Console.WriteLine("Error: No Matching Information in the Sitecode and R03sites files!")
End If
End If
End If
Loop Until line Is Nothing
Here is the output:
\Dell>bcmass
line = BEC,test.beckley.com,19233
Start processing loop
BEC , BEC
s=test.beckley.com p=19233
Array populated... Enter if then statement
Error: No Matching Information in the Sitecode and R03sites files!
line = BIR,test.birmingham.com,19230
Start processing loop
BEC , BIR
s=test.birmingham.com p=19230
Array populated... Enter if then statement
Error: No Matching Information in the Sitecode and R03sites files!
line =
Start processing loop
|
|
|
|
|
If Trim(Sites) = Trim(strSiteCode) Then
That should be
If Trim(Site1) = Trim(strSiteCode) Then
You need to slow down, think what you are trying to achieve, and look at exactly what each line is doing. Rather than using Console.WriteLine to see what is going on, you should use the debugger step by step, so you can see exactly what is happening.
And in the second loop (as I explained previously) BEC will never be equal to BIR .
|
|
|
|
|
That totally makes sense. I just didn't change sites to site1 in all instances. I know that BEC will never equal BIR, R03sites has numerous sites and what I wanted to do was loop through all the sites in R03sites and write an error to the console on non-matching items and process the match. I just don't know how to do what I want a better way. I am sure you could make the loop stop when it finds a match but I don't know how to do it yet. I am still new to programming and have never worked with 2 text files at once, I have mostly just used text files to read computer names or ip addresses and then do something straightforward with it or write text to a log file. I appreciate the help. I left work but will give this a try tomorrow.
|
|
|
|
|
Thanks for the help. It worked perfectly.
|
|
|
|
|
|
This line If Trim(Sites) = Trim(strSiteCode) Then is supposed to find the matching entry in both Sites and R03sites files ie. BEC , BEC and then process the shortcut creation and write to console if no match is found. Then loop through the rest of the file. I would like to learn how to make it stop when it finds the match but I can't even make it work the way I need it to yet.
|
|
|
|
|
Member 11866893 wrote: Then loop through the rest of the file. I would like to learn how to make it stop
break;
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi folks,
I am new to vb. I need help to create a vb.net windows service to download latest new uploaded files from server after every 1 minute to local computer . This code download same only single file once the service started. BUT I want to windows service detect each latest new file uploaded on server and download it automatically. Below is my code. Kindly help me.
Imports System
Imports System.IO
Imports System.Net
Imports System.Timers
Imports System.Threading
Public Class Service1
Dim timerSchedule As System.Timers.Timer
Protected Overrides Sub OnStart(ByVal args() As String)
' MyThread = New Threading.Thread(AddressOf Execute)
timerSchedule = New System.Timers.Timer(1000)
AddHandler timerSchedule.Elapsed, AddressOf timerSchedule_Elapsed
timerSchedule.Start()
End Sub
Protected Overrides Sub OnStop()
End Sub
Private Sub timerSchedule_Elapsed(ByVal pSender As Object, ByVal pArgs As System.Timers.ElapsedEventArgs)
Try
timerSchedule.Stop()
'call my a function to do the scheduled task
FTPDownloadFile()
Catch ex As Exception
Finally
timerSchedule.Start()
End Try
End Sub
Private Sub FTPDownloadFile()
Dim ftpuri As String = ""
Dim downloadpath As String = ""
Dim ftpusername As String = ""
Dim ftppassword As String = ""
'Create a WebClient.
Dim request As New WebClient()
' Confirm the Network credentials based on the user name and password passed in.
request.Credentials = New NetworkCredential("root", "")
'Read the file data into a Byte array
Dim bytes() As Byte = request.DownloadData("http://localhost/salary_system/")
Try
' Create a FileStream to read the file into
For Each i As String In downloadpath
Dim DownloadStream As FileStream = IO.File.Create("C:\download\*.php")
' Stream this data into the file
DownloadStream.Write(bytes, 0, bytes.Length)
' Close the FileStream
DownloadStream.Close()
Next
Catch ex As Exception
MsgBox(ex.Message)
Exit Sub
End Try
MsgBox("Process Complete")
End Sub
End Class
|
|
|
|
|
Hi,
Posting the question three times only annoys people.
Have you set "Allow service to interact with the desktop", if not your service may hang on the msgbox's.
|
|
|
|
|
firstly i posted question in another forum, so one member suggested me to post question in vb forum. That's why i posted here. and window service is interacting with desktop. it is working fine only problem is that it is downloading only specif file when the service is started. i want to download each new uploaded file.
I am not trying to annoy people. i have problem. pls help me
|
|
|
|
|
Member 12957775 wrote: suggested me to post question in vb forum
Yes and what else were you told to do? Did you do either one? I would guess not as this is the same code with the exact same problem.
Member 12957775 wrote: i have problem. pls help me
If you don't listen we are just wasting our time.
Speed of sound - 1100 ft/sec
Speed of light - 186,000 mi/sec
Speed of stupid - instantaneous.
|
|
|
|
|
Hi folks,
I am new to vb. I need help to create a vb.net windows service to download latest new uploaded files from server after every 1 minute to local computer . This code download same only single file once the service started. BUT I want to windows service detect each latest new file uploaded on server and download it automatically. Below is my code. Kindly help me.
Imports System
Imports System.IO
Imports System.Net
Imports System.Timers
Imports System.Threading
Public Class Service1
Dim timerSchedule As System.Timers.Timer
Protected Overrides Sub OnStart(ByVal args() As String)
' MyThread = New Threading.Thread(AddressOf Execute)
timerSchedule = New System.Timers.Timer(1000)
AddHandler timerSchedule.Elapsed, AddressOf timerSchedule_Elapsed
timerSchedule.Start()
End Sub
Protected Overrides Sub OnStop()
End Sub
Private Sub timerSchedule_Elapsed(ByVal pSender As Object, ByVal pArgs As System.Timers.ElapsedEventArgs)
Try
timerSchedule.Stop()
'call my a function to do the scheduled task
FTPDownloadFile()
Catch ex As Exception
Finally
timerSchedule.Start()
End Try
End Sub
Private Sub FTPDownloadFile()
Dim ftpuri As String = ""
Dim downloadpath As String = ""
Dim ftpusername As String = ""
Dim ftppassword As String = ""
'Create a WebClient.
Dim request As New WebClient()
' Confirm the Network credentials based on the user name and password passed in.
request.Credentials = New NetworkCredential("root", "")
'Read the file data into a Byte array
Dim bytes() As Byte = request.DownloadData("http://localhost/salary_system/")
Try
' Create a FileStream to read the file into
For Each i As String In downloadpath
Dim DownloadStream As FileStream = IO.File.Create("C:\download\*.php")
' Stream this data into the file
DownloadStream.Write(bytes, 0, bytes.Length)
' Close the FileStream
DownloadStream.Close()
Next
Catch ex As Exception
MsgBox(ex.Message)
Exit Sub
End Try
MsgBox("Process Complete")
End Sub
End Class
|
|
|
|
|
Okay, so I have an idea for a little quick addition to a program that I thought could be simple but I cant exactly find any information on it nor confirmation that it is even possible in visual basic.
I am using vb6, but I can also use .net if it this is not possible in vb6.
So here is my question. I have a text box where a number will be inputted from another aspect of the whole program. The inputted text will be 84 characters long. I need a command button to delete the first 46 and last 4 characters. For the grand finale, I need that number to be inverted!
Now, I have racked my brain for weeks on this little debacle and have not come up with anything.
I hope that someone has an idea on what to do with this.
I have also been thinking, I can due without the inverting of the numbers because I'm not sure that is t all possible. Or, if I need to, I can make it into two command buttons.
This is merely an aspect of a larger working program so Id rather not re write this in another language. However, it is also just for fun (hence why I wanted to do it in vb6) so I'm not going to cry if it doesn't work out.
Thanks for any help at all
|
|
|
|
|
Member 12961546 wrote: any help at all
Okay... since you didn't say what you needed help with...
Member 12961546 wrote: I'm not sure that is t all possible
Yes, it is possible. VB6 has a Left, Right and StrReverse functions so I fail to see why you think that this is a problem at all.
Speed of sound - 1100 ft/sec
Speed of light - 186,000 mi/sec
Speed of stupid - instantaneous.
|
|
|
|
|
In a vb.net 2010 application, I have the following code that works sometimes:
Dim txtOrigAddress As String = _attendanceLetterOrig.Substring(CInt(_attendanceLetterOrig.IndexOf("ADDR_BEG")), _attendanceLetterOrig.IndexOf("ADDR_END") - _attendanceLetterOrig.IndexOf("ADDR_BEG"))
Dim txtOrigAddress As String = _attendanceLetterOrig.Substring(CInt(_attendanceLetterOrig.IndexOf("ADDR_NEXT")),4)
The problem is the folllowing values do not exist:
_attendanceLetterOrig.IndexOf("ADDR_BEG")
_attendanceLetterOrig.IndexOf("ADDR_END")
_attendanceLetterOrig.Substring(CInt"ADDR_NEXT")
What kind of an edit can I use to check if the 3 values listed above actually exist? I want to prevent application errors.
Would you show me the code to see if the values really exist?
|
|
|
|
|
|
If the substring isn't found, IndexOf returns -1 . You'll need to find and store each index first, then check that they're not -1 before calling Substring .
Also, IndexOf already returns an Integer . There's no need to call CInt .
Dim startIndex As Integer = _attendanceLetterOrig.IndexOf("ADDR_BEG")
Dim endIndex As Integer = _attendanceLetterOrig.IndexOf("ADDR_END", startIndex)
If startIndex <> -1 AndAlso endIndex <> -1 Then
Dim txtOrigAddress As String = _attendanceLetterOrig.Substring(startIndex, endIndex - startIndex)
End If
Your second example makes no sense. The IndexOf method returns the index of the start of the matched substring, if found. So _attendanceLetterOrig.IndexOf("ADDR_NEXT") returns the index of "A" , and _attendanceLetterOrig.Substring(..., 4) will always return "ADDR" .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
The source code for the menu strip like notepad menu strip.
|
|
|
|
|