Good day everybody! I'm currently trying to figure something out in excel before implementing in it VBScript. I have to mathematically transpose a few cells (10*10 or 5r*10c) in a matrice:
------------------------------- | .. | .. | .. | .. | .. | .. | | 21 | 22 | 23 | 24 | 25 | .. | | 11 | 12 | 13 | 14 | 15 | .. | | 1 | 2 | 3 | 4 | 5 | .. | -------------------------------
Must become
------------------------------- | .. | .. | .. | .. | .. | .. | | 3 | 13 | 23 | 33 | 43 | .. | | 2 | 12 | 22 | 32 | 42 | .. | | 1 | 11 | 21 | 31 | 41 | .. | -------------------------------
Now I'm not a mathematician (I'm more ore less a programmer at the moment), but I came up with: F(y)=((MOD(x,10)-1)*10)+(1+((x-MOD(x,10))/10))
(x
is the value in the pre-block a the top, y
is the value in the pre-block below.) Now this works fine up to a certain point (e.g. 10
).
In VBScript, I wrote the below at first:
Function GetPosInSrcRack(Pos) Dim PlateDef(9), x, y, i, tmp ' Plate Definition ReDim tmp(UBound(PlateDef)) For x = 0 To UBound(PlateDef) PlateDef(x) = tmp Next i = 1 For x = 0 To UBound(PlateDef) For y = 0 To UBound(PlateDef(x)) PlateDef(x)(y) = i i = (i + 1) Next Next 'Dim msg ' Check definition 'For x = 0 To (UBound(PlateDef)) ' msg = Join(PlateDef(x), ", ") & vbCrLf & msg 'Next ' Get the Position y = (pos Mod 10) x = ((pos - y) / 10) GetPosInSrcRack = PlateDef(y)(x) End Function
Which, of course, works but is crappy.
Using the above formula I would write:
Function GetPosInSrcRack(Pos) Pos = (((Pos MOD 10)-1)*10)+(1+((Pos - (Pos MOD 10))/10)) End Function
But like I said, this still is incorrect (10 gives -8) Can somebody help me?