|
THANKS FOR YOUR SUGGESTION GOOD BYE
|
|
|
|
|
Typing everything is all CAPS is seen as screaming whatever you're saying. Don't do it.
The only code you're going to get is the code you write. Nobody is going to do your work for you.
|
|
|
|
|
Are you ready? Here's the code: G-53
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I require to assign an Action to a method.
I can do this in C# without problem.
But when I port the C# code to VB.NET I fail at one line.
My company has a VB.NET application where we require this solution.
I have created a small and reproducible solution regarding this in both a C# and VB.
Of course this is not the real solution I have, but the problem is same.
C# code
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
var foo = new Foo();
foo.Bar = Qux;
foo.Baz();
}
static void Qux()
{
Console.WriteLine(nameof(Qux));
}
}
class Foo
{
public Action Bar { get; set; }
public void Baz()
{
Bar();
}
}
} VB.NET code
Module Module1
Sub Main()
Dim foo As Foo = New Foo()
foo.Bar = Qux()
foo.Baz()
End Sub
Sub Qux()
Console.WriteLine(NameOf(Qux))
End Sub
Class Foo
Private b As Action
Public Property Bar() As Action
Get
Return b
End Get
Set(ByVal value As Action)
b = value
End Set
End Property
Public Sub Baz()
b()
End Sub
End Class
End Module The compile error message: Expression does not produce a value
VB.NET is not my primary language and I'm sure I have made some very basic mistake.
I don't like to ask for a solution, but I cannot find the correct way to do this.
Please provide me with the correct solution to fix this.
|
|
|
|
|
In your VB.NET code, you're calling the Qux method, and attempting to store the return value in an Action . But the method doesn't return a value, so there's nothing to store, and you get a compiler error.
You need to use the AddressOf operator to create a delegate pointing to the required method:
foo.Bar = AddressOf Qux AddressOf Operator - Visual Basic | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks!
It I tried the AddressOf earlier, but beeing used to C# I added parentheses as well: AddressOf(Baz) .
Of course that doesn't work
|
|
|
|
|
Strange, it was working, then it stopped.
When I add DESC, the sort gets scrambled. I checked my RDLC for a sort somewhere, but it's a straight feed.
I tried Desc, Asc works
Dim dVa As New DataView(tableInventoryItems)
Select Case pSorting
Case InventoryEriReportDialog.Type_EriReportR2_Sort.ITEM
dVa.Sort = "FITEMNO"
Case InventoryEriReportDialog.Type_EriReportR2_Sort.ATD3YA
dVa.Sort = "FATD3Y_A DESC"
Case InventoryEriReportDialog.Type_EriReportR2_Sort.PTDA
dVa.Sort = "FPTD0_A DESC"
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
According to the documentation[^], it should work. What does the data look like?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
The column is a decimal. It must another sort call that I didn't see later on in the chain. I'll keep looking.
125.63
25.39
512.69
12.58
14.59
789.00
If I use Asc or nothing
12.58
12.59
14.59
125.63
512.69
789.00
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
Are you sure it's actually a decimal, and not a string representation of a decimal?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I didn't check that. And I should double check the RDLC, and dataset I made as well.
That's a excellent suggestion.
tableInventoryItems.Columns.Add(New DataColumn("FATD0_Q", Type.GetType("System.Int32")))
tableInventoryItems.Columns.Add(New DataColumn("FATD0_A", Type.GetType("System.Decimal")))
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
jkirkerx wrote:
Type.GetType("System.Int32")
Type.GetType("System.Decimal") NB: You can simplify that to:
tableInventoryItems.Columns.Add(New DataColumn("FATD0_Q", GetType(Integer)))
tableInventoryItems.Columns.Add(New DataColumn("FATD0_A", GetType(Decimal))) GetType Operator - Visual Basic | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I didn't know that.
give it a try, that would be nicer than using a string.
I just compiled it, and deployed it on the customer machine, and all of a sudden it works.
Worked on my machine as well when testing. I changed the enumerator for the sorts to more descriptive names, and that was it.
I don't know.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
hmm, didn't like it.
my Type.GetType wants a string + 7 overloads.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
... typeof( int )
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
|
I think I get it now. Will try it again.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
I'm using this example from ChilKat, using his dll to connect to a server by ssh. it works perfectly the problem is that i want to run a list of commands from a textbox
VB.NET SSH Remote Shell Multiple Commands[^]
So i have a textbox with some monitoring commands:
<pre> For x = 0 To MonitorCommandsToRun.Lines.Count - 1
' Open a session channel. (It is possible to have multiple
' session channels open simultaneously.)
channelNum = ssh.OpenSessionChannel()
If (channelNum < 0) Then
output.AppendText(ssh.LastErrorText & vbNewLine)
Exit Sub
End If
success = ssh.SendReqShell(channelNum)
If (success <> True) Then
output.AppendText(ssh.LastErrorText & vbNewLine)
Exit Sub
End If
success = ssh.ChannelSendString(channelNum, MonitorCommandsToRun.Lines(x).ToString & vbCrLf, "ansi")
If (success <> True) Then
output.AppendText(ssh.LastErrorText & vbNewLine)
Exit Sub
End If
' Retrieve and display the output.
success = ssh.ChannelReceiveUntilMatch(channelNum, myPrompt, "ansi", True)
If (success <> True) Then
output.AppendText(ssh.LastErrorText & vbNewLine)
Exit Sub
End If
cmdOutput = ssh.GetReceivedText(channelNum, "ansi")
If (ssh.LastMethodSuccess <> True) Then
output.AppendText(ssh.LastErrorText & vbNewLine)
Exit Sub
End If
success = ssh.ChannelSendEof(channelNum)
If (success <> True) Then
output.AppendText(ssh.LastErrorText & vbNewLine)
Exit Sub
End If
n = ssh.ChannelReadAndPoll(channelNum, pollTimeoutMs)
If (n < 0) Then
output.AppendText(ssh.LastErrorText & vbNewLine)
Exit Sub
End If
' Close the channel:
success = ssh.ChannelSendClose(channelNum)
If (success <> True) Then
output.AppendText(ssh.LastErrorText & vbNewLine)
Exit Sub
End If
output.AppendText(cmdOutput & vbNewLine)
Next
this looks ugly and the program hangs, not sure if i need to remove the channelNum check or avoid closing it but i just want it to resume doing one command per line.
My entire code is like chilkat's with this for inside it.
thanks in advance
|
|
|
|
|
Private Sub btnTotalCost_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTotalCost.Click
lblTotalCost.Text = "YOU HAVE ORDERED:" & vbNewLine
lblTotalCost.Text = lblTotalCost.Text & "ROOM TYPE" & vbNewLine & "--------" & vbNewLine
If radLuxury.Checked Then
lblTotalCost.Text = lblTotalCost.Text & "Luxury = $210" & vbNewLine
ElseIf radSuperior.Checked Then
lblTotalCost.Text = lblTotalCost.Text & "Superior = $150" & vbNewLine
Else
lblTotalCost.Text = lblTotalCost.Text & "Standard = $110" & vbNewLine
End If
lblTotalCost.Text = lblTotalCost.Text & vbNewLine & "MEAL OPTIONS" & vbNewLine & "--------" & vbNewLine
If chkBufferBreakfast.Checked Then
lblTotalCost.Text = lblTotalCost.Text & "Buffer Breakfast = $40" & vbNewLine
End If
If chkBufferDinner.Checked Then
lblTotalCost.Text = lblTotalCost.Text & "Buffer Dinner = $60" & vbNewLine
End If
lblTotalCost.Text = lblTotalCost.Text & vbNewLine & "AMENITIES" & vbNewLine & "--------" & vbNewLine
If chkInternet.Checked Then
lblTotalCost.Text = lblTotalCost.Text & "Internet = $10" & vbNewLine
End If
If chkEntertainment.Checked Then
lblTotalCost.Text = lblTotalCost.Text & "Entertainment = $20" & vbNewLine
End If
If chkSpaServices.Checked Then
lblTotalCost.Text = lblTotalCost.Text & "Spa Services = $50" & vbNewLine
End If
End Sub
|
|
|
|
|
|
WELL, I WAnt to create a project in vb6 regarding a leap year (user will enter any year and the computer will have identify if that is a leap year or not).
|
|
|
|
|
Permission granted.
Why on earth are you using VB6? It's been dead for quite a long time now.
|
|
|
|
|
|
Devam Dani wrote: WELL, I WAnt to create a project in vb6 No.
No. Thousand times, no. You don't.
VB.NET is available for free, and would run on any platform that supports VB6. You don't write anything "new" in VB6. There's not even an excuse to do so. Anyone who does should be punished. Not just with jail, but with torture.
Also sounds like a school-assignment; if it is, find a new school - dump them today, without explanation. VB6 is dead for a long time, and there's better and free alternatives. VB6 was never free. If you see a copy, it is probably a pirated one.
If it is a school, please contact me.
But no. Not ever should you write in VB6. If the devil comes and demands it; say no and tell him it is out of service. No longer supported.
VB's not pinin'! 'B's passed on! This language is no more! It has ceased to be! 'VB6's expired and gone to meet its maker! 'VB6's a stiff! Bereft of life, 'B rests in pieces! If you hadn't nailed it to the perch VB6'd be pushing up the daisies! Its metabolic processes are now history! VB6's off the twig! VB6's kicked the bucket, VB6 shuffled off its mortal coil, run down the curtain and joined the bleedin' choir invisible!! THIS IS AN EX-LANGUAGE!!
No. No. No.
Devam Dani wrote: user will enter any year and the computer will have identify if that is a leap year or not Easy.
But VB6? No. We don't even discuss it. Just, no.
Would be simple in the free VB.NET, but VB6?
No.
Did I mention VB6 is a bad idea? For everything? Whatever your question on VB6, the answer is
noIf it is a school, ask your fakkin' money back. Send me their address; I will have a word. Or DWORD. Or several. ..but I will close them if this their modus operandi.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Loving the Monty Python references
|
|
|
|