🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: be.comp.programming
3 messages
3 total messages Started by Lucas Fri, 13 Aug 2004 07:37
VB-script niet in orde ?
#2221
Author: Lucas
Date: Fri, 13 Aug 2004 07:37
39 lines
2032 bytes
Het onderstaand VB-scriptje zet een prijskolom van een Excel file om naar
dit formaat "00000000000.00"
(via data-pump in MySQL)
Maar bij de conversie blijkt dat sommige waarden met 1.00 verhoogd zijn. Dus
ik vermoed dat er ergens
een klein foutje zit in dit script. Omdat ik zelf niets afweet van VB, vraag
ik het daarom aan jullie.

Met vriendelijke groeten,

Lucas


**********************************************************************
'  Visual Basic Transformation Script
'  Copy each source column to the
'  destination column
'**********************************************************************
Function Main()
 Euro = DTSSource("F4")
 Zero="00000000000"
 Val=CInt(Euro)
 Resu=Cstr(Val)
' Resu=Cstr(Euro)
 Carac=Len(Resu)
 Comma=Int((Euro-Int( Euro ))*100)
 Nzer=11-Carac
 if Comma  >9  then Pab=Mid(Zero,1,Nzer) & Mid(Resu,1,Carac) & "."&Comma
else Pab=Mid(Zero,1,Nzer) & Mid(Resu,1,Carac) & "." & "0"&Comma
 DTSDestination("TCAPAB") = Pab
 Main = DTSTransformStat_OK
End Function



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.737 / Virus Database: 491 - Release Date: 11/08/2004
Re: VB-script niet in orde ?
#2222
Author: TRAX
Date: Sat, 14 Aug 2004 20:41
19 lines
1781 bytes
Lucas wrote:
> Het onderstaand VB-scriptje zet een prijskolom van een Excel file om
> naar dit formaat "00000000000.00"
> (via data-pump in MySQL)
> Maar bij de conversie blijkt dat sommige waarden met 1.00 verhoogd
> zijn. >
>


>  Comma=Int((Euro-Int( Euro ))*100)

Deze waarde zal in elk geval al afgerond worden tot op de eenheden, dus als
die waarde bvb 5.6 is zal het 6 worden. een int is een geheel getal en
gezien hier een cast gedaan wordt naar een int waarde is de uitkomst altijd
een geheel getal. Dus hier zullen sommige waarden veranderd worden.
Misschien helpt dit je een beetje op weg, ik heb namelijk geen flauw idee
wat de bedoeling is van het stukje script :)
Je kan het in elk geval oplossen door te casten naar Double ipv naar Int,
doubles kunnen immers kommagetallen zijn.
Re: VB-script niet in orde ?
#2238
Author: Alain Cloet
Date: Thu, 19 Aug 2004 17:23
34 lines
2036 bytes
"Lucas" <luc.logghe@pandora.be> schreef in bericht
news:411c6fd7$0$294$ba620e4c@news.skynet.be...
> Het onderstaand VB-scriptje zet een prijskolom van een Excel file om naar
> dit formaat "00000000000.00"
> (via data-pump in MySQL)

> Function Main()
>  Euro = DTSSource("F4")
>  Zero="00000000000"
>  Val=CInt(Euro)

Zoals Trax meldde: Int (of CInt) rond af ... Mogelijkse workaround:

    Val=CInt(Euro-0.5)

>  Resu=Cstr(Val)
> ' Resu=Cstr(Euro)
>  Carac=Len(Resu)
>  Comma=Int((Euro-Int( Euro ))*100)
>  Nzer=11-Carac
>  if Comma  >9  then Pab=Mid(Zero,1,Nzer) & Mid(Resu,1,Carac) & "."&Comma
> else Pab=Mid(Zero,1,Nzer) & Mid(Resu,1,Carac) & "." & "0"&Comma
>  DTSDestination("TCAPAB") = Pab
>  Main = DTSTransformStat_OK
> End Function

Als 'format' hier bruikbaar is, kan het veel korter...(in VBA lukt het, maar
zelf heb ik geen ervaring met MySql)

Function Main()
    DTSDestination("TCAPAB")=Format( DTSSource("F4");"00000000000.00")
    Main = DTSTransformStat_OK
End Function
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads