Solved

error in string.

Posted on 2007-04-02
1
138 Views
Last Modified: 2010-04-16
If I put 200401

it gives me 20042





Public Function IncrementDate(ByVal DtPeriod As String, ByVal IncrementAmount As Integer) As String

Dim strResults As String

Dim intYear As Integer

Dim intMonth As Integer

intYear = Int32.Parse(DtPeriod.Substring(0, 4))

intMonth = Int32.Parse(DtPeriod.Substring(4, 2))

intMonth += IncrementAmount

If intMonth > 12 Then

intYear += 1

intMonth -= 12

End If

strResults = intYear.ToString & intMonth.ToString

Return strResults

End Function
0
Comment
Question by:mathieu_cupryk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 18838841
that is because int.Tostring does not keep leading 0

strResults = intYear.ToString & intMonth.ToString().PadLeft(2, "0")
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to use spatial data types in SQL Server Database project 2 66
C# Formatting DateTime String Value 5 68
Create a Dropdown list with sub group 10 43
Need help with a query 14 53
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question