11 Replies - 778 Views - Last Post: 24 February 2012 - 11:29 PM Rate Topic: -----

#1 damdimdum  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 42
  • Joined: 20-February 12

How to Change Substring IndexOf?

Posted 23 February 2012 - 10:28 PM

I'm filter my Listview with cboMonth
my format date MM/dd/yyyy

Now I want change my format date dd-MM-yyyy
But it does'nt work
plz hlp me
  For Each itm As ListViewItem In itms '// loop thru all itms in Array.          
                With itm.SubItems(1).Text '// check Column2.Text
                    If CInt(.Substring(0, .IndexOf("/"))) = CInt(selCoolMonth) Then '// get all text prior to the first "/".
                        selCoolListView.Items.Add(itm)                        
                    End If
                End With

Change to
 If CInt(.Substring(1, .IndexOf("-"))) = CInt(selCoolMonth) Then ' Not work why

tx

Is This A Good Question/Topic? 0
  • +

Replies To: How to Change Substring IndexOf?

#2 _HAWK_  Icon User is online

  • Master(Of Foo)
  • member icon

Reputation: 957
  • View blog
  • Posts: 3,682
  • Joined: 02-July 08

Re: How to Change Substring IndexOf?

Posted 23 February 2012 - 10:50 PM

Easy to change the format:

Dim dt As Date = #2/23/2012#
Console.WriteLine(dt.ToString("dd-MM-yyyy"))

This post has been edited by _HAWK_: 23 February 2012 - 10:51 PM

Was This Post Helpful? 0
  • +
  • -

#3 damdimdum  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 42
  • Joined: 20-February 12

Re: How to Change Substring IndexOf?

Posted 23 February 2012 - 11:09 PM

my format date have change to dd-MM-yyyy

but now is problem my filter from cbmonth ... how to read the range from indexOf
I want cbMonth read only MM in dd-MM-YYYY
 If CInt(.Substring(1, .IndexOf("-"))) = CInt(selCoolMonth) Then 

I change .IndexOf("-" & "-") or .indexOf("MM")or .indoxOf("dd-") or .indexOf("dd-??-yyyy")
All cannot use, like my cbmonth not read the MM in .indexOf
MM range dd- MM - yyyy how can we read only MM
Was This Post Helpful? 0
  • +
  • -

#4 damdimdum  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 42
  • Joined: 20-February 12

Re: How to Change Substring IndexOf?

Posted 23 February 2012 - 11:17 PM

if I change to MM-dd-yyyy it can work after .substring = 0 indexOf("-")
but if month in second subtring dd-MM-yyyy blank like cannot read
Was This Post Helpful? 0
  • +
  • -

#5 strawhat89  Icon User is offline

  • The Watcher Outside Your Window


Reputation: 247
  • View blog
  • Posts: 1,784
  • Joined: 11-July 11

Re: How to Change Substring IndexOf?

Posted 23 February 2012 - 11:18 PM

well you can use the split funtion like

Dim arrDate As String() = Split(stringName, "-")



now you can access the MM value through arrDate(1)...

try this out, i think it'll work.
Was This Post Helpful? 0
  • +
  • -

#6 damdimdum  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 42
  • Joined: 20-February 12

Re: How to Change Substring IndexOf?

Posted 23 February 2012 - 11:44 PM

this my problem with cbmonth value
why value can 2.0 ?
my indexof are no problem value = 2

Private Sub cbMonth_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbMonth.SelectedValueChanged
        Dim test As Double = cbMonth.SelectedIndex + 1
        With test
            If test > 0 Then filterCoolListView(LvList, test)
        End With
    End Sub

Was This Post Helpful? 0
  • +
  • -

#7 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1385
  • View blog
  • Posts: 4,461
  • Joined: 25-September 09

Re: How to Change Substring IndexOf?

Posted 24 February 2012 - 05:05 AM

Is this a string containing a date and all you want is the month from it?
Have you tried casting it to a date datatype so that you can get the month from it

dim strDate as String= "24/02/2012"
dim dt as date
if DateTime.TryParse(strDate, dt) Then
  Messagebox.Show(dt.Month)
End If

Was This Post Helpful? 0
  • +
  • -

#8 damdimdum  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 42
  • Joined: 20-February 12

Re: How to Change Substring IndexOf?

Posted 24 February 2012 - 05:32 AM

also same can display.. blank
format date like no problem, if MM-dd-yyyy Substring = 0 ...ok
or dd-MM-yyy Substring = 0 is ok ....> only it filter my date

the problem is when I change Substring = 1
blank listview
This like
 If CInt(.Substring(0, .IndexOf("-"))) = CInt(selCoolMonth) Then

.Subtring not work if change to 1
Was This Post Helpful? 0
  • +
  • -

#9 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1385
  • View blog
  • Posts: 4,461
  • Joined: 25-September 09

Re: How to Change Substring IndexOf?

Posted 24 February 2012 - 06:22 AM

OK, I'm not grasping what you're exactly doing. Can you show some screen shots of your form and describe what you want to happen when?

I'm not sure why you would switch from 0 to 1 as the starting point of the substring but again, I'm not sure what it is you're actually trying to do.
Was This Post Helpful? 0
  • +
  • -

#10 damdimdum  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 42
  • Joined: 20-February 12

Re: How to Change Substring IndexOf?

Posted 24 February 2012 - 06:57 AM

All is ok only
cannot change to dd-MM-yyy

I can change to dd-MM-yyyy
but filter month must disable
or mean cannot filter by month.

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#11 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1385
  • View blog
  • Posts: 4,461
  • Joined: 25-September 09

Re: How to Change Substring IndexOf?

Posted 24 February 2012 - 07:20 AM

So in the Tanggal column you want it to display 21-02-2012 instead?

If so then you can try what _HAWK_ was describing

after the listview populates try
for each itm as listviewitem in yourlistview.Items
 itm.SubItems(1).Text = CDate(itm.SubItems(1).Text).ToString("dd-MM-yyyy")
next


There's not much in the way of error handling here, it is basically just reformatting the column. You would have to take into consideration the current format and parse it properly to switch back and forth if needed or to handle invalid dates.

This post has been edited by CharlieMay: 24 February 2012 - 07:20 AM

Was This Post Helpful? 0
  • +
  • -

#12 damdimdum  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 42
  • Joined: 20-February 12

Re: How to Change Substring IndexOf?

Posted 24 February 2012 - 11:29 PM

Ok never mind it.

try
If date format dd-MM-yyyy then
my cbmonth filter all transation with my date like screen shot not my month

Finaly I use format date MM-dd-yyyy

Catch ex As Exception
msgbox( tx to ALL '" & _HAWK_ & CharlieMay & "" )

End Try
return MM-dd-yyyy

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1