6 Replies - 552 Views - Last Post: 17 May 2012 - 01:25 PM Rate Topic: -----

#1 nighttrain  Icon User is offline

  • D.I.C Regular

Reputation: 5
  • View blog
  • Posts: 289
  • Joined: 22-September 10

couple of questions about vba and vb.net

Posted 17 May 2012 - 05:41 AM

Hello i got couple of question to You i am converting from vba to vb.net and my questions are:

1) in vba i had:
Date - 26


how to do the same in vb.net ?

2)in vba i had
Dim At As String
At = Cells(x, 1)


What i did was:
Dim At As String
At = Cells(x, 1).Value



it's ok?

3) Sometimes i had in VBA not declared 'At'
At = Cells(x, 1)



So to questions 2 and 3 is ok if i make variable as string and equal it to Cells(x,1).Value or?

Please of help.

Is This A Good Question/Topic? 0
  • +

Replies To: couple of questions about vba and vb.net

#2 m_wylie85  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 96
  • View blog
  • Posts: 899
  • Joined: 15-October 10

Re: couple of questions about vba and vb.net

Posted 17 May 2012 - 05:52 AM

HI is the date coming from a date time picker?

if so you could use:

datetimepicker.Value = DateTime.Now.AddYears(-26)


Else

Dim DateNowMinus26 As DateTime = DateTime.Today.AddDays(-26)



For the cells:

Dim At As String = ""

At = datagridview.Rows(x).Cells(1).Value.ToString

This post has been edited by m_wylie85: 17 May 2012 - 05:54 AM

Was This Post Helpful? 0
  • +
  • -

#3 nighttrain  Icon User is offline

  • D.I.C Regular

Reputation: 5
  • View blog
  • Posts: 289
  • Joined: 22-September 10

Re: couple of questions about vba and vb.net

Posted 17 May 2012 - 05:58 AM

Not its a 'Date' from VBA in vb.net i cant just do Date - 26 :)

It's needed to do it "toString()" ? Its not enough if is :

Cells().Value?


I am working with excel cells not with datagridview :)
Dim At As String = ""	 
At = .Cells(0).Value.ToString



other question if i loop from vb.net in excel rows
better of use is:
if ..
Cells().Value = Nothing
...



or
if ..
Cells().Value.ToString() = Nothing
...


This post has been edited by nighttrain: 17 May 2012 - 06:02 AM

Was This Post Helpful? 0
  • +
  • -

#4 m_wylie85  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 96
  • View blog
  • Posts: 899
  • Joined: 15-October 10

Re: couple of questions about vba and vb.net

Posted 17 May 2012 - 06:05 AM

Hey about the ToString no you don'y really need it. It's just me and my coding style :bigsmile:

About the date that is the way have used them in the past however you may want to read below it should clear up any question you have:

http://www.dotnetper...me-format-vbnet

About the cells

If Cells().Value Is DBNull.Value Or Nothing Then
'Do What Ever
End IF


Might be the best for that again i don't think Tostring will make a difference

This post has been edited by m_wylie85: 17 May 2012 - 06:12 AM

Was This Post Helpful? 0
  • +
  • -

#5 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 572
  • View blog
  • Posts: 2,985
  • Joined: 19-May 09

Re: couple of questions about vba and vb.net

Posted 17 May 2012 - 06:24 AM

You shouldn't use = Nothing in VB.Net. See here for reasons.

This post has been edited by BobRodes: 17 May 2012 - 06:25 AM

Was This Post Helpful? 0
  • +
  • -

#6 nighttrain  Icon User is offline

  • D.I.C Regular

Reputation: 5
  • View blog
  • Posts: 289
  • Joined: 22-September 10

Re: couple of questions about vba and vb.net

Posted 17 May 2012 - 08:57 AM

Ok, so what should i use instead of:
if ..
Cells(x, y).Value = Nothing
...



Was This Post Helpful? 0
  • +
  • -

#7 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 572
  • View blog
  • Posts: 2,985
  • Joined: 19-May 09

Re: couple of questions about vba and vb.net

Posted 17 May 2012 - 01:25 PM

It doesn't occur to you to read the link I sent you before asking that?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1