473,385 Members | 1,640 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

I need a little help here.

I want to convert this C# Linq Query into VB.NET

void Load() {
int i = 1;
var q = from P in Persons
select new System.Windows.Forms.ListViewItem( P.Name, i++ );
}

I did this:

Sub Load()
Dim I As Integer = 1
Dim q = from P in Persons _
Select New ListViewItem(P.Name, i++
? )
End Sub

My problem is how I can use the ++ Operator in Vb?

Thanks in advance.

Jun 27 '08 #1
4 833
Carlos, the ++ operator in C# uses the current value, if it's involved in an
expression of any kind, and then increments it after use. So in the C# code,
it will use the i value of 1 as an argument in the select, and then will set
it to 2 afterwards.

So the equivalent in VB.Net would be:

Sub Load()

Dim i As Integer = 1

Dim q = from P in Persons _
Select New ListViewItem(P.Name, i)
i += 1

' Other code follows, presumably...

End Sub
Tom Dacon
Dacon Software Consulting
"Carlos Yakimov" <ma*******@cantv.netwrote in message
news:uR**************@TK2MSFTNGP05.phx.gbl...
>I want to convert this C# Linq Query into VB.NET

void Load() {
int i = 1;
var q = from P in Persons
select new System.Windows.Forms.ListViewItem( P.Name,
i++ );
}

I did this:

Sub Load()
Dim I As Integer = 1
Dim q = from P in Persons _
Select New ListViewItem(P.Name, i++
? )
End Sub

My problem is how I can use the ++ Operator in Vb?

Thanks in advance.

Jun 27 '08 #2

"Tom Dacon" <td****@community.nospamwrote in message
news:uH**************@TK2MSFTNGP02.phx.gbl...
Carlos, the ++ operator in C# uses the current value, if it's involved in
an expression of any kind, and then increments it after use. So in the C#
code, it will use the i value of 1 as an argument in the select, and then
will set it to 2 afterwards.

So the equivalent in VB.Net would be:

Sub Load()

Dim i As Integer = 1

Dim q = from P in Persons _
Select New ListViewItem(P.Name, i)
i += 1

' Other code follows, presumably...

End Sub
Tom Dacon
Dacon Software Consulting
"Carlos Yakimov" <ma*******@cantv.netwrote in message
news:uR**************@TK2MSFTNGP05.phx.gbl...
>>I want to convert this C# Linq Query into VB.NET

void Load() {
int i = 1;
var q = from P in Persons
select new System.Windows.Forms.ListViewItem( P.Name,
i++ );
}

I did this:

Sub Load()
Dim I As Integer = 1
Dim q = from P in Persons _
Select New ListViewItem(P.Name,
i++ ? )
End Sub

My problem is how I can use the ++ Operator in Vb?

Thanks in advance.

I tried this and the C# version would provide an incremented value for each
listviewitem created. So you would expect a collection of listviewitems
where the imageIndex would start at 1 and increment for each item.

When you try the code in VB (and I have no idea why) you end up with a list
of listviewitems and each has an imageIndex of 2. If I change the code to i
+=2 then the items have an imageIndex of 3. It seems that the final
increment is what is used as if the value is not created until used.

LS

Jun 27 '08 #3

"Lloyd Sheen" <a@b.cwrote in message
news:On**************@TK2MSFTNGP04.phx.gbl...
>
"Tom Dacon" <td****@community.nospamwrote in message
news:uH**************@TK2MSFTNGP02.phx.gbl...
>Carlos, the ++ operator in C# uses the current value, if it's involved in
an expression of any kind, and then increments it after use. So in the C#
code, it will use the i value of 1 as an argument in the select, and then
will set it to 2 afterwards.

So the equivalent in VB.Net would be:

Sub Load()

Dim i As Integer = 1

Dim q = from P in Persons _
Select New ListViewItem(P.Name, i)
i += 1

' Other code follows, presumably...

End Sub
Tom Dacon
Dacon Software Consulting
"Carlos Yakimov" <ma*******@cantv.netwrote in message
news:uR**************@TK2MSFTNGP05.phx.gbl...
>>>I want to convert this C# Linq Query into VB.NET

void Load() {
int i = 1;
var q = from P in Persons
select new System.Windows.Forms.ListViewItem( P.Name,
i++ );
}

I did this:

Sub Load()
Dim I As Integer = 1
Dim q = from P in Persons _
Select New ListViewItem(P.Name,
i++ ? )
End Sub

My problem is how I can use the ++ Operator in Vb?

Thanks in advance.


I tried this and the C# version would provide an incremented value for
each listviewitem created. So you would expect a collection of
listviewitems where the imageIndex would start at 1 and increment for each
item.

When you try the code in VB (and I have no idea why) you end up with a
list of listviewitems and each has an imageIndex of 2. If I change the
code to i +=2 then the items have an imageIndex of 3. It seems that the
final increment is what is used as if the value is not created until used.

LS
Ok I think you can use a function to do the incrementing:

Dim Persons() As String = {"Him", "Her", "Them"}
Dim ii As Integer = 0

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim tst = From t In Persons _
Select New ListViewItem(t, GiveMeAnInt(t))

Dim i As Integer = tst.Count
Dim tl As List(Of ListViewItem) = tst.ToList
End Sub

Private Function GiveMeAnInt(ByVal tmp As String) As Integer
ii += 1
Return ii
End Function
Once again though the imageIndex values are in fact 4,5,6 which I think
confirms that somehow the values are being put in at a time other than what
I would think is correct. Linq has its values but I don't think that in
the case of VB that this works very well.
Tracing the call to GiveMeAnInt shows 6 calls. Seems like the .ToList
recalls the values so if you want to create the list you would have to put
an ii=0 prior to the .ToList call. My last iteration also removed the need
to have a parameter to the GiveMeAnInt. All in all quite a kludge.

Lloyd Sheen

Jun 27 '08 #4
You know, I just realized that I was completely off base with my suggestion.
I haven't actually used Linq (we're still on 2.0), and I was just thinking
that what I was seeing in the OP's code was a simple function call. Clearly
the constructor's being called once for each hit in the select. So my
suggestion wasn't worth a damn.

Sorry 'bout that.

Tom Dacon


Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: OZ | last post by:
Hi, I am new C++ and need a little help with a public domain program that is suppose to perform a byte swap. I am receiving the following error messages during the compile process with Microsoft...
5
by: mr.iali | last post by:
Hi Everyone I would like to get into software developent using a programming language like c++, java or pl/sql for oracle. I have no idea where to start from. Which language is there more...
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
17
by: EkteGjetost | last post by:
This is definitely not the smart thing to do as far as my learning goes, but desperate situations call for desperate measures. The final lab for my introduction to C programming class is due...
22
by: OHM \( Terry Burns \) | last post by:
I was thinking about community the other day, and wondering what would be the holy grail for a developer in need. I mean, we do get help here, but its done on a best endeavours basis and its really...
0
by: U S Contractors Offering Service A Non-profit | last post by:
Brilliant technology helping those most in need Inbox Reply U S Contractors Offering Service A Non-profit show details 10:37 pm (1 hour ago) Brilliant technology helping those most in need ...
33
by: STILL LEARNING | last post by:
I'm not sure if this can even be done, but what prompts the question is my desire to be able to create an "Uber Link" script/code of some sort, such that even if the html page contains nothing but...
5
by: Grant Olson | last post by:
I'm feeling a little guilty here. I spent a lot of my free time last year working on an x86 compiler for python. I made a reasonable amount of progress, but my interests wandered off into other...
5
by: bean330 | last post by:
Hey, I'm somewhat new to C# and I need a little help, please! I'm selecting a bunch of records, setting properties on a COM executable and then calling a method on that executable to run. I...
1
by: Voxus | last post by:
(This is for C++ guys not C) Hi, I’m a new user and I haven't paid any attention to setting my details, as I am just here to get a little help on programming a small project I’m working on. I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.