|
I don't why I didn't think of that. Or perhaps I did but tried to use it after the GroupBy resulting in an error.
Thanks Richard!
21st Century Globalism has become Socialism on a planetary scale, in which the unequal treaties of the past have come back into play.
|
|
|
|
|
All-
I have a datagridview on a form, with associated textboxes and such - as the user selects a row in the dgv, the textboxes show the appropriate record - for updating information on that record.
On a main menu form - I have a production line, and model year value that determines what data the user sees.
I am applying a filter to the bindingsource for the dgv to limit the information based on the production line and model year for which the user works on.
my filter looks like this -
me.TblPCRBindingSource.Filter = "ModelYear = " & (myear) And "Line = " & CInt(txtLine.Text)
where myear is a double as we can have 2017.5 model year (for mid year changes) and line I'm reading a textbox, but the datatype in the table is integer - so I convert.
If I do filter for one field - it works for that field. as soon as I add "AND" and the other field - they cancel each other out and I get ALL records.
I'm baffled as to why - banging head on wall.
please help-
thank you -
|
|
|
|
|
Member 11089831 wrote: "ModelYear = " & (myear) And "Line = " & CInt(txtLine.Text)
Shouldn't there be a space before the "Line?
Otherwise the resultfilter contents becomes "ModelYear = 2017Line = 0", and 2017Line will be an invalid value for a integer-field in the table, making the filter invalid.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
yes, there should be a space - this is how I currently have it -
me.TblPCRBindingSource.Filter = "ModelYear = " & (myear) And "Line = " & CInt(txtLine.Text)
it however, does not work.
it's like it turned the filter off.
if I make them separate lines like this:
Me.TblPCRBindingSource.Filter = "Line = " & CInt(txtLine.Text)
Me.TblPCRBindingSource.Filter = "ModelYear = " & (myear)
then only 1 filter works - usually the last one - as it follows order of operations.
the msdn documentation tell you to use And as I have above, but when I do with different data types .. they don't filter at all.
|
|
|
|
|
Shouldn't the And be inside the string?
me.TblPCRBindingSource.Filter = "ModelYear = " & (myear) & " And Line = " & CInt(txtLine.Text)
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
If I do add the "and" within the statement, I get an end of statement expected error.
Me.TblPCRBindingSource.Filter = "ModelYear = " & (myear) "And Line = " & CInt(txtLine.Text)
so this, doesn't work.
|
|
|
|
|
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
|
|
|
|