|
Here's an alternative to the solution you seek; get a full list of all the PC's, and then use LINQ to query out the ones that are servers. You may also get a better query from a network-admin; it is querying the AD after all.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Learning Threading, Invoke, Delegate and MethodInvoker ...
0) I use Visual Basic 2017.
1) I can press Button1 or Button2 randomly: works!
2) After the first round I can only press Button2. Button1 no longer works!
3) Who can indicate IN THE CODE where the error is?
4) I search for information everywhere on the internet, but what exactly Invoke, Delegate and MethodInvoker do, is not completely clear to me …
5) Thank you …
Public Class Form1
Dim Number1 As Integer
Dim Number2 As Integer
Dim Thread1 As System.Threading.Thread
Dim Thread2 As System.Threading.Thread
Private Delegate Sub UpdateLabel1Delegate(ByVal Number1 As Integer)
Private Delegate Sub UpdateLabel2Delegate(ByVal Number2 As Integer)
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Thread1 = New System.Threading.Thread(AddressOf CountUp)
Thread1.Start()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Thread2 = New System.Threading.Thread(AddressOf CountDown)
Thread2.Start()
End Sub
Private Sub CountUp()
Do Until Number1 = 1000
Number1 = Number1 + 1
UpdateLabel1Text(Number1)
Loop
End Sub
Private Sub CountDown()
Number2 = 1000
Do Until Number2 = 0
Number2 = Number2 - 1
UpdateLabel2Text(Number2)
Loop
End Sub
Private Sub UpdateLabel1Text(ByVal Number1 As Integer)
If Label1.InvokeRequired Then
Me.BeginInvoke(New UpdateLabel1Delegate(AddressOf UpdateLabel1Text), Number1)
Else
Label1.Text = Number1
Me.Refresh()
End If
End Sub
Private Sub UpdateLabel2Text(ByVal Number2 As Integer)
If Label2.InvokeRequired Then
Me.BeginInvoke(New UpdateLabel2Delegate(AddressOf UpdateLabel2Text), Number2)
Else
Label2.Text = Number2
Me.Refresh()
End If
End Sub
End Class
|
|
|
|
|
You're initializing the number in one sub, but not the other.
Private Sub CountUp()
Number1 = 0
Do Until Number1 = 1000
Number1 = Number1 + 1
UpdateLabel1Text(Number1)
Loop
End Sub Enjoy the festivities and keep on learning, you're doing well
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Thanks Eddy!
Very, very stupid of me !!
Eric
|
|
|
|
|
Member 11112814 wrote: Very, very stupid of me !! It's not, we all have those moments; you're searching for an error, and there clearly is none. I wasn't searching for one, just looking for the difference that you told me would be there.
It was a good formulated question with description of expected and actual results.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
My final assigment is about client server using timer. if client and server are connected with 30 minute then communication between clienrt and server will be disconnect. but i couldnt find timer function on internet. i have finished with client serverbut not yet to part using timer. if u can help me, please reply me as soon as possible.
Thank You.
modified 22-Dec-18 22:18pm.
|
|
|
|
|
|
thakn you for your reply
|
|
|
|
|
Unless you love getting spam emails, NEVER post your email address in a public forum. I suggest you edit your post and remove it now.
|
|
|
|
|
I'm creating an project which can show me the complete list of "Installed" software in my system and "Uninstalled" them please help me to find.
|
|
|
|
|
|
|
There is no "complete" list; not every application registers an uninstaller with Windows.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
The SQL code am using is
Private Sub Command8_Click()
Dim SQL As String
SQL = "SELECT tblVisit.PatientID, tblPatients.Firstname, tblPatients.Lastname" _
& "DateDiff('yyyy',[tblPatients]![Birthday],Now()) AS Age, tblVisit.[Date Visit]" _
& "tblVisit.Diagnosis" _
& "[First Name] & ' ' & [Last Name] AS [Prescriber Names] FROM tblPatients INNER JOIN (tblDoctor INNER JOIN tblVisit ON tblDoctor.DoctorID = tblVisit.DoctorID) ON tblPatients.PatientID = tblVisit.PatientID" _
& "WHERE [Firstname] = '" & Me.txtKeywords & "' "
Me.subClientList.Form.RecordSource = SQL
Me.subClientList.Form.Requery
End Sub
The error that is coming up is..
The error is runtime error '3075'
syntax error (missing operator) in query expression 'tblvist'.[DateVisit]tblVist.Diagnosis[First Name]& ' ' [Last Name]'
The
[First Name]& ' ' [Last Name]' are from a table prescribers and the
tblVist.Diagnosis is an attachment column in the table visit and the
tblvist'.[DateVisit]tblVist is a column of visit dates
|
|
|
|
|
I think you need a comma after each item.
|
|
|
|
|
Thanks alot for your input. Because of you. I managed to troubleshoot and I have got it working. thanks alot
|
|
|
|
|
You're using string concatenation to build the query. This alone is a bad idea as you are very vulnerable to making mistakes and you open the database up to being destroyed due to SQL Injection attacks.
Your code looks like this:
SQL = "SELECT tblVisit.PatientID, tblPatients.Firstname, tblPatients.Lastname" _
& "DateDiff('yyyy',[tblPatients]![Birthday],Now()) AS Age, tblVisit.[Date Visit]" _
& "tblVisit.Diagnosis" _
& "[First Name] & ' ' & [Last Name] AS [Prescriber Names] FROM tblPatients INNER JOIN (tblDoctor INNER JOIN tblVisit ON tblDoctor.DoctorID = tblVisit.DoctorID) ON tblPatients.PatientID = tblVisit.PatientID" _
& "WHERE [Firstname] = '" & Me.txtKeywords & "' "
This results in a query string that looks like this. Examine this query statement closely and you're going to find lots of problems. You're missing spaces between words and messed up the concatenation in places.
SELECT tblVisit.PatientID, tblPatients.Firstname, tblPatients.LastnameDateDiff('yyyy',[tblPatients]![Birthday],Now()) AS Age, tblVisit.[Date Visit]tblVisit.Diagnosis[First Name] & ' ' & [Last Name] AS [Prescriber Names] FROM tblPatients INNER JOIN (tblDoctor INNER JOIN tblVisit ON tblDoctor.DoctorID = tblVisit.DoctorID) ON tblPatients.PatientID = tblVisit.PatientIDWHERE [Firstname] = 'SqlInjectionAttack' "
Now, Google for "SQL Injection Attack" to find out why what you did was so wrong, then Goggle for "VB.NET SQL parameterized queries" to find out what to do about it.
|
|
|
|
|
Public Class Form1
Dim attempt As Integer
Private Sub BtnLogIn_Click(sender As Object, e As EventArgs) Handles BtnLogIn.Click
If CBUser.Text = "Mineomyn" And TBPass.Text = "lemsilog" Then
MsgBox("Log in successful!", MsgBoxStyle.Information)
TBPass.Clear()
GBAddons.Enabled = True
GBPizza.Enabled = True
RichTextBox1.Enabled = True
BtnCalculate.Enabled = True
BtnCompleteOrder.Enabled = True
BtnClearOrder.Enabled = True
TBAmount.Enabled = True
TBChange.Enabled = True
TBTotal.Enabled = True
BtnChange.Enabled = True
ElseIf CBUser.Text = "Lemsilog" And TBPass.Text = "lemsilog" Then
MsgBox("Log in successful!", MsgBoxStyle.Information)
TBPass.Clear()
GBAddons.Enabled = True
GBPizza.Enabled = True
RichTextBox1.Enabled = True
BtnCalculate.Enabled = True
BtnCompleteOrder.Enabled = True
BtnClearOrder.Enabled = True
TBAmount.Enabled = True
TBChange.Enabled = True
TBTotal.Enabled = True
BtnChange.Enabled = True
ElseIf CBUser.Text = "Lemzipon" And TBPass.Text = "lemsilog" Then
MsgBox("Log in successful!", MsgBoxStyle.Information)
TBPass.Clear()
GBAddons.Enabled = True
GBPizza.Enabled = True
RichTextBox1.Enabled = True
BtnCalculate.Enabled = True
BtnCompleteOrder.Enabled = True
BtnClearOrder.Enabled = True
TBAmount.Enabled = True
TBChange.Enabled = True
TBTotal.Enabled = True
BtnChange.Enabled = True
Else attempt = attempt + 1
End If
If attempt = 1 Then
MsgBox("Incorrect user or pass. Attempts left: 2", MsgBoxStyle.Exclamation)
TBPass.Clear()
GBAddons.Enabled = False
GBPizza.Enabled = False
RichTextBox1.Enabled = False
ElseIf attempt = 2 Then
MsgBox("Incorrect user or pass. Attempts left: 1", MsgBoxStyle.Exclamation)
TBPass.Clear()
GBAddons.Enabled = False
GBPizza.Enabled = False
RichTextBox1.Enabled = False
ElseIf attempt = 3 Then
MsgBox("Incorrect user or pass. You have reached maximum attempts to log in. Try again later.", MsgBoxStyle.Critical)
TBPass.Clear()
GBAddons.Enabled = False
GBPizza.Enabled = False
RichTextBox1.Enabled = False
BtnLogIn.Enabled = False
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
GBPizza.Enabled = False
GBAddons.Enabled = False
RichTextBox1.Enabled = False
BtnCalculate.Enabled = False
BtnCompleteOrder.Enabled = False
BtnClearOrder.Enabled = False
TBAmount.Enabled = False
TBChange.Enabled = False
TBTotal.Enabled = False
BtnChange.Enabled = False
End Sub
Private Sub calculate()
Dim cost As Double
Dim order As String
If Radsmall.Checked Then
cost = Radsmall.Tag
order = "18 inch"
ElseIf Radmedium.Checked Then
cost = Radmedium.Tag
order = "24 inch"
Else
cost = Radlarge.Tag
order = "28 inch"
End If
If CB15Coke.Checked Then cost += CB15Coke.Tag
If CB1Coke.Checked Then cost += CB1Coke.Tag
If CBCrust.Checked Then cost += CBCrust.Tag
If CBextracheese.Checked Then cost += CBextracheese.Tag
If CBmushroom.Checked Then cost += CBmushroom.Tag
If CBsingledrink.Checked Then cost += CBsingledrink.Tag
TBTotal.Text = cost
Dim display As String = "You order a " & order
If ComboPizza.Text = "Pepperoni" Then display += " pepperoni pizza"
If ComboPizza.Text = "4 Cheese" Then display += " 4 cheese pizza"
If ComboPizza.Text = "All meat" Then display += " all meat pizza"
If ComboPizza.Text = "Hawaiian" Then display += " hawaiian pizza"
If ComboPizza.Text = "Classic Italian" Then display += " classic italian pizza"
If ComboPizza.Text = "New York Style" Then display += " New York style pizza"
If ComboPizza.Text = "Pure Beef" Then display += " pure beef pizza"
If CB15Coke.Checked Then display += " with 1.5L Coke"
If CB1Coke.Checked Then display += " with 1L Coke"
If CBCrust.Checked Then display += " with tuff crust"
If CBextracheese.Checked Then display += " with extra cheese"
If CBmushroom.Checked Then display += " with mushroom"
If CBsingledrink.Checked Then display += " with single drink"
Me.RichTextBox1.Text = display
End Sub
Private Sub BtnCalculate_Click(sender As Object, e As EventArgs) Handles BtnCalculate.Click
calculate()
End Sub
Private Sub BtnCancelOrder_Click(sender As Object, e As EventArgs) Handles BtnClearOrder.Click
TBAmount.Clear()
TBChange.Clear()
TBTotal.Clear()
Radlarge.Checked = False
Radmedium.Checked = False
Radsmall.Checked = False
CB15Coke.Checked = False
CB1Coke.Checked = False
CBCrust.Checked = False
CBextracheese.Checked = False
CBmushroom.Checked = False
CBsingledrink.Checked = False
ComboPizza.Text = ""
Me.RichTextBox1.Clear()
End Sub
Private Sub BtnChange_Click(sender As Object, e As EventArgs) Handles BtnChange.Click
TBChange.Text = Val(TBTotal.Text - TBAmount.Text)
End Sub
Private Sub BtnCompleteOrder_Click(sender As Object, e As EventArgs) Handles BtnCompleteOrder.Click
MsgBox("Order is complete. Your order will be delivered to you within 45 minutes. Thank you!")
End Sub
End Class
The "Calculate Order" button will do the total order. Then I have to manually put the amount on the "Amount Paid" textbox to get the change. Now, what I wanted to do is to assign the enter key so that I can just press enter after typing the amount and don't have to hover the mouse and click the "Amount Paid" button. I don't know the codes for it, and where should i put the codes, on the textbox or on the button? The accept button property is already used on my "Log in" button. Please help me. xD Thanks in advance!
|
|
|
|
|
|
Hello !
Is there any fast way to create a list of obj1(Integer,string) , where the first field is an integer from 1-2000 , and the second field is the same string. , so the list should be : (1,"a") , (2,"a"),(3,"a")........(2000,"a").
I know that with a for loop can I create this , but i'm asking if there's a more fast way.
Thank you !
|
|
|
|
|
Depends what you mean by "fast".
If you mean you want to save on typing, then try LINQ:
Dim myList As List(Of obj1) = Enumerable.Range(1, 2000).Select(Function(i) New obj1(i, "a")).ToList()
If you want the code to execute faster, then a For loop is probably your best bet. If you know the size of the list, then make sure you specify the initial capacity, to avoid having to reallocate the internal storage over and over again.
List<T>.Capacity Property (System.Collections.Generic) | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
for loop is faster than Linq ?
In other occasions , the for loop was very slower than Linq
|
|
|
|
|
desanti wrote: In other occasions , the for loop was very slower than Linq Measured by you on a timer?
One is a simple loop, the other a call to an interface to return an object on each iteration. Which of the two do you think would be faster?
Also, instead of having a list, this would probably be done faster by casting the int to a string when you need it, instead of having it in memory in a non-array.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Hi,
Wonder if there's a better approach to fill a Treeview recursively. Following snippet fills the Treeview but if I need an extra level I'd have to create yet another Sub. There must be a way of doing it recursively? Also I'm not able to show CategoryName on every node (please see tree representations below):
IdCategory CategoryName ParentCategory
15 Uncategorized 0
50 Animals 0
51 Plants 0
52 Dogs 50
53 Small 52
54 Medium 52
55 Large 52
56 Trees 51
57 Flowers 51
58 White 55
59 Brown 55
I call FillRootLevel and get the following:
0
Animals
Plants
Uncategorized
50
Dogs
51
Flowers
Trees
52
Large
Medium
Small
55
Brown
White
Private Sub FillRootLevel()
tvCategories.Nodes.Clear()
dtCategories = obj.ListCategories().Tables("Data")
For Each dr As DataRow In dtCategories.Rows
Dim node As New TreeNode With {
.Text = dr("IdCategory"),
.Tag = dr("CategoryName")
}
tvCategories.Nodes.Add(node)
FillParentCategories(node.Tag, node)
Next
End Sub
Private Sub FillParentCategories(ByVal strNodeTag As String, ByVal parentnode As TreeNode)
dtParentCategories = obj.ListParentCompanies().Tables("Data")
For Each dr As DataRow In dtParentCategories.Rows
Dim node As New TreeNode With {
.Text = dr("ParentCategory"),
.Tag = dr("ParentCategory")
}
parentnode.Nodes.Add(node)
FillCategories(node.Tag, node)
Next
End Sub
Private Sub FillCategories(ByVal strParentCategory As String, ByVal parentnode As TreeNode)
dtCategories = obj.ListCategories(strParentCategory).Tables("Datos")
For Each dr As DataRow In dtCategories.Rows
Dim node As New TreeNode With {
.Text = dr("CategoryName"),
.Tag = dr("CategoryName")
}
parentnode.Nodes.Add(node)
Next
End Sub
I'd need:
Uncategorized
Animals
Dogs
Large
Brown
White
Medium
Small
Plants
Flowers
Trees
Searched quite a bit for a solution but couldn't find a VB.NET / C# acceptable one.
Thanks for any help you may provide!
Sergio
modified 7-Dec-18 18:33pm.
|
|
|
|
|
When you create a node, name it using the value of "IdCategory". When reading the next item, take parentId, and search the entire treeview for a node that has that name as its Id. (FindNode or similar would do, without having to use recursion).
If it exists, add the current item as a child to that node.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|