This code yields `0` as the value no matter what roman numeral I enter. Why is this so? - python-3.6

import re
d = { ' M ' :1000, ' CM ' :900, ' D ' :500, ' CD ' :400, ' C ' :100, ' XC ':90,
' L ' :50, ' XL ' :40, ' X ' :10, ' IX ' :9, ' V ' :5, ' IV ' :4, ' I ' :1}
pattern = re.compile(r"""(?x)
(M{0,3})(CM)?
(CD)?(D)?(C{0,3})
(XC)?(XL)?(L)?(X{0,3})
(IX)?(IV)?(V)?(I{0,3})""")
num = input( ' Enter Roman numeral: ' ).upper()
m = pattern.match(num)
sum = 0
for x in m.groups():
if x!=None and x!= '' :
if x in [ ' CM ' , ' CD ' , ' XC ' , ' XL ' , ' IX ' , ' IV ' ]:
sum+=d[x]
elif x[0] in ' MDCLXVI ' :
sum+=d[x[0]]* len(x)
print(sum)
When I run this code it gives 0 as the output no matter what Roman numeral I enter.
What did I do wrong? Is white spaces the issue?
For example: Enter Roman numeral I
0 Enter Roman numeral X
0

Related

Formatting Mac Address in MS Access

New to MS Access. Had a question regarding formatting of a MAC Address in one of my Access forms. There is a field I have set up using an input mask aa:aa:aa:aa:aa:aa;;a where users can manually enter a 48 bit hexidecimal address. e.x 11:44:5E:33:53:AF.
However sometimes there are missing values that occur in this data entry e.x 0:A:B:11:22:C (happens from time to time) but I would like be able to automatically fill the missing values with leading zeros to be like 00:0A:0B:11:22:0C.
I realize that this may not be possible through just MS Access Input masks, but all of the VBA codes and after updates code building I have been looking at so far have not lead me to the desired format.
Thanks for your time and appreciate any help in this!
I tried Format(fieldname, "00000000") code, but it just fills from the left-hand side instead of between the colons. e.x 00:00:0A:B1:12:2C instead of the desired 00:0A:0B:11:22:0C.
My function FormatMacAddress is for you:
' Formats a MAC address using one of the four de facto formats used widely.
' Thus, the format can and will be defined by the specified delimiter to use.
' The default is no delimiter and uppercase.
' Optionally, the case of the returned string can be specified as lowercase.
'
' Examples:
' None -> "1234567890AB"
' Dot -> "1234.5678.90AB"
' Dash -> "12-34-56-78-90-AB"
' Colon -> "12:34:56:78:90:AB"
'
' Lowercase -> "1234567890ab"
'
' 2019-09-23, Cactus Data ApS, Gustav Brock
'
Public Function FormatMacAddress( _
ByRef Octets() As Byte, _
Optional Delimiter As IpMacAddressDelimiter, _
Optional TextCase As VbStrConv = VbStrConv.vbProperCase) _
As String
Dim LastFrame As Integer
Dim ThisFrame As Integer
Dim FrameLength As Integer
Dim Index As Integer
Dim Symbol As String
Dim MacAddress As String
' Only accept an array with six octets.
If LBound(Octets) = 0 And UBound(Octets) = OctetCount - 1 Then
' Calculate the frame length.
FrameLength = DigitCount / DelimiterFrameCount(Delimiter)
' Format the octets using the specified delimiter.
For Index = LBound(Octets) To UBound(Octets)
ThisFrame = (Index * OctetLength) \ FrameLength
Symbol = ""
If LastFrame < ThisFrame Then
Symbol = DelimiterSymbol(Delimiter)
LastFrame = ThisFrame
End If
MacAddress = MacAddress & Symbol & Right("0" & Hex(Octets(Index)), OctetLength)
Next
End If
If MacAddress <> "" Then
Select Case TextCase
Case VbStrConv.vbLowerCase
MacAddress = StrConv(MacAddress, TextCase)
Case Else
' Leave MacAddress in uppercase.
End Select
End If
FormatMacAddress = MacAddress
End Function
As it requires a Byte() input, you may need the function MacAddressParse as well:
' Parses a string formatted MAC address and returns it as a Byte array.
' Parsing is not case sensitive.
' Will by default only accept the four de facto standard formats used widely.
'
' Examples:
' "1234567890AB" -> 1234567890AB
' "1234.5678.90AB" -> 1234567890AB
' "12-34-56-78-90-AB" -> 1234567890AB
' "12:34:56:78:90:AB" -> 1234567890AB
'
' If argument Exact is False, a wider variation of formats will be accepted:
' "12-34:56-78:90-AB" -> 1234567890AB
' "12 34 56-78 90 AB" -> 1234567890AB
' "56 78 90 AB" -> 0000567890AB
' "1234567890ABDE34A0" -> 1234567890AB
'
' For unparsable values, the neutral MAC address is returned:
' "1K34567890ABDEA0" -> 000000000000
'
' 2019-09-23, Cactus Data ApS, Gustav Brock
'
Public Function MacAddressParse( _
ByVal MacAddress As String, _
Optional Exact As Boolean = True) _
As Byte()
Dim Octets() As Byte
Dim Index As Integer
Dim Expression As String
Dim Match As Boolean
' Delimiters.
Dim Colon As String
Dim Dash As String
Dim Dot As String
Dim Star As String
' Create neutral MAC address.
ReDim Octets(0 To OctetCount - 1)
' Retrieve delimiter symbols.
Colon = DelimiterSymbol(ipMacColon)
Dash = DelimiterSymbol(ipMacDash)
Dot = DelimiterSymbol(ipMacDot)
Star = DelimiterSymbol(ipMacStar)
If Exact = True Then
' Verify exact pattern of the passed MAC address.
Select Case Len(MacAddress)
Case TotalLength1
' One frame of six octets (no delimiter).
Expression = Replace(Space(DigitCount), Space(1), HexPattern)
Match = MacAddress Like Expression
If Match = True Then
' MAC address formatted as: 0123456789AB.
End If
Case TotalLength3
' Three frames of two octets.
Expression = Replace(Replace(Replace(Space(DigitCount / FrameLength3), Space(1), Replace(Replace(Space(FrameLength3), Space(1), HexPattern), "][", "]" & Star & "[")), "][", "]" & Dot & "["), Star, "")
Match = MacAddress Like Expression
If Match = True Then
' MAC address formatted as: 0123.4567.89AB.
MacAddress = Replace(MacAddress, Dot, "")
End If
Case TotalLength6
' Six frames of one octets.
Expression = Replace(Replace(Replace(Space(DigitCount / FrameLength6), Space(1), Replace(Replace(Space(FrameLength6), Space(1), HexPattern), "][", "]" & Star & "[")), "][", "]" & Colon & "["), Star, "")
Match = MacAddress Like Expression
If Match = True Then
' MAC address formatted as: 01:23:45:67:89:AB.
MacAddress = Replace(MacAddress, Colon, "")
Else
Expression = Replace(Expression, Colon, Dash)
Match = MacAddress Like Expression
If Match = True Then
' MAC address formatted as: 01-23-45-67-89-AB.
MacAddress = Replace(MacAddress, Dash, "")
End If
End If
End Select
Else
' Non-standard format.
' Clean MacAddress and try to extract six octets.
MacAddress = Replace(Replace(Replace(Replace(MacAddress, Colon, ""), Dash, ""), Dot, ""), Space(1), "")
Select Case Len(MacAddress)
Case Is > DigitCount
' Pick leading characters.
MacAddress = Left(MacAddress, DigitCount)
Case Is < DigitCount
' Fill with leading zeros.
MacAddress = Right(String(DigitCount, "0") & MacAddress, DigitCount)
End Select
' One frame of six possible octets.
Expression = Replace(Space(DigitCount), Space(1), HexPattern)
Match = MacAddress Like Expression
If Match = True Then
' MAC address formatted as: 0123456789AB.
End If
End If
If Match = True Then
' Fill array Octets.
For Index = LBound(Octets) To UBound(Octets)
Octets(Index) = Val("&H" & Mid(MacAddress, 1 + Index * OctetLength, OctetLength))
Next
End If
MacAddressParse = Octets
End Function
Full code at GitHub: VBA.MacAddress.

Trim Function doesn't remove any spaces from any side

I try to trim spaces in Calc using a macro.
The Trim function doesn't seem to work
I tried using Trim, LTrim, RTrim but same result.
Anybody have an idea of where is wrong?
oCSL is "Arang and the Magistrate"
oCSR and z should also be like oCSL after Trim but still stays "Arang and the Magistrate   "
Code below:
Dim oAC As Object, oC As Object, oAS As Object, oCSL As String, oCSR As String
Dim oASn As Integer
Dim CellRangeAddress As New com.sun.star.table.CellRangeAddress
Dim CellAddress As New com.sun.star.table.CellAddress
oC = ThisComponent
oAS = oC.getcurrentcontroller.ActiveSheet
oASn = oC.getCurrentController().getActiveSheet().getRangeAddress().sheet
Dim Ll As Integer, Lc As Integer, r As Integer
Dim z As String, y As String
Ll = 400
Lc = 0
r = 400
' Read Each Left Side Line
Do
Do
' Locate Position For Right Side
Do
oCSL = Trim(UCase(oAS.getCellByPosition(Lc, Ll).String)) ' oSCL Value Returned "Arang and the Magistrate"
oCSR = Trim(UCase(oAS.getCellByPosition(7, r).String)) ' oCSR Value Returned "Arang and the Magistrate   "
z = RTrim(oAS.getCellByPosition(7, r).String) ' z Returns Also "Arang and the Magistrate   "
If strcomp(oCSL, oCSR) < 0 Then
ThisComponent.CurrentController.Select(oAS.getCellByPosition(7, r)) ' Reposition Selected Area
'ThisComponent.CurrentController.Select(oAS.getCellByPosition(Lc, Ll)) ' Reposition Selected Area
MsgBox ("At " & r & " Not Found " & Chr(13) & oCSL) ' Not Found
' Insert New Movie
Exit Do
else
If UCase(oCSL) = UCase(OcSR) Then
ThisComponent.CurrentController.Select(oAS.getCellByPosition(7, r)) ' Reposition Selected Area
'MsgBox ("At " & r & " Same Value " & oCSL) ' Same Value
r = r + 1
Exit Do
else
r = r + 1
End If
End If
Loop While Lc <= 4
Lc = Lc + 1
Loop While Lc <= 4
Ll = Ll + 1 ' Next Line
Lc = 0 ' Reset Column
Loop While oCSL <> "" ' getCellByPosition Starts From Col 0 Row 0
I found the reason.
After using Asc() in order to figuring out if it's spaces and it wasn't spaces but special characters.
Sorry for bothering everybody.

MS Access - Combine varchar column with int column - ASP.net VB.net

I'm using an oledb connection string to connect my asp.net code to an access db
I can't seem to convert combine the 3 fields - ProductID(NUMBER)
ProductCode(TEXT), ProdDescription(TEXT)
Dim strQuery As String = "SELECT ProductID, (CAST(ProductID AS TEXT) + ' - '
+ ProductCode + ' - ' + ProdDescription) AS [Prod]
FROM [FG - End Product Codes]
ORDER BY ProductCode;"
I've also tried
(CAST(ProductID AS VARCHAR(10)) + ' - ' + ProductCode + ' - ' + ProdDescription) AS [Prod]
And
(CONVERT(ProductID, TEXT)) + ' - ' + ProductCode + ' - ' + ProdDescription) AS [Prod]
AND
(CAST(ProductID) AS VARCHAR(10)) + ' - ' + ProductCode + ' - ' + ProdDescription) AS [Prod]
AND
(CAST([ProductID] AS TEXT) + ' - ' + [ProductCode] + ' - ' + [ProdDescription]) AS [Prod]
Error msg: System.Data.OleDb.OleDbException:
'IErrorInfo.GetDescription failed with E_FAIL(0x80004005).'
error code : -2147467259
I seen the same error in another question but theirs seem to have some reserve keyword problem, If mine is the same, what is My reserved Keyword and where is it in my code?
thanks in advance
That's because you try to use T-SQL against Access which uses Access SQL. So, try this:
Dim strQuery As String = "SELECT ProductID, ProductID & ' - ' &
ProductCode & ' - ' & ProdDescription AS [Prod]
FROM [FG - End Product Codes]
ORDER BY ProductCode;"

PL/SQL VARCHAR2 Max Length

I can't seem to use a VARCHAR2 of more than 4000 chars in 11G, but I see that I should be able to get to 32776.
PROCEDURE prcName
(piCoSite IN CHAR
,piRaciId IN NUMBER
,piDept IN VARCHAR2
,poRecordset OUT SYS_REFCURSOR) AS
locSql1 VARCHAR2(32000 CHAR);
BEGIN
locSql1 :=
'SELECT' ||
' H.TABLE_HEAD_ID ' ||
' ,H.TABLE_HEAD_DEPT ' ||
' ,H.TABLE_HEAD_DESCRIPTION ' ||
' ,H.TABLE_HEAD_STATUS ' ||
' ,H.TABLE_HEAD_SCOPE ' ||
' ,H.TABLE_HEAD_ORIGINATOR ' ||
' ,H.TABLE_HEAD_SUB_CATEGORY ' ||
' ,H.TABLE_HEAD_HIGH_RISK ' ||
' ,TRIM(C0.CNTCT_FIRSTNAME) || '' '' || TRIM(C0.CNTCT_SURNAME) wsRaisedBy ' ||
' ,(SELECT COUNT(*) FROM TABLE_EMPLOYEES E WHERE E.TABLE_EMPS_CO_SITE = H.TABLE_HEAD_CO_SITE AND E.TABLE_EMPS_ID = H.TABLE_HEAD_ID) wsNoEmployees ' ||
' ,(SELECT COUNT(*) FROM TABLE_TASKS T WHERE T.TABLE_TASK_CO_SITE = H.TABLE_HEAD_CO_SITE AND T.TABLE_TASK_ID = H.TABLE_HEAD_ID) wsNoActions ' ||
' FROM TABLE_HEADER H ' ||
' LEFT JOIN CONTACTS C0 ' ||
' ON C0.CNTCT_CO_SITE = H.TABLE_HEAD_CO_SITE ' ||
' AND C0.CNTCT_CODE = H.TABLE_HEAD_ORIGINATOR ' ||
' WHERE H.TABLE_HEAD_CO_SITE = ''' || piCoSite || '''' ||
' AND (H.TABLE_HEAD_ID = ''' || piRaciId || '''' || ' OR ''' || piRaciId || ''' = 0) ' ||
' AND (H.TABLE_HEAD_DEPT IN (''' || piDept || ''' ) OR ''' || piDept || ''' IS NULL ) ' ||
' AND (H.TABLE_HEAD_ORIGINATOR IN (' || piUser || ' ) OR ''' || piUser || ''' IS NULL ) ' ||
' AND (H.TABLE_HEAD_STATUS IN (' || piStatus || ' ) OR ''' || piStatus || ''' IS NULL ) ' ||
' ORDER BY TABLE_HEAD_ID ';
dbms_output.put_line(locSql1);
OPEN poRecordset FOR locSql1;
When I copy/paste the locSql1 variable it's nowhere near 32000 chars, but it's getting truncated.
Is there something within the Database to change or am I missing something?
Thanks.

(asp.net) Gridview dynamical columns put margin on one of them

Been trying to style my gridview for some time. It gets data dynamical and would then able to put margin (padding) on one of the columns.
Is this even possibly to do?
Because when I try to get the columns count it allways return 0.
Is there some other way to make this?
Also would like to cellSpace but only Horizontal not vertical any suggestions there?
gwResult.DataSource = dvData
gwResult.DataBind()
gwResult.GridLines = GridLines.None
'Dim desc As Integer
'gwResult.RowStyle.HorizontalAlign = HorizontalAlign.Left
'headCell = gwResult.HeaderRow.Cells.Count
'rows = gwResult.Rows.Count
'For i As Integer = 0 To headCell - 1
' gwResult.HeaderRow.Cells(i).HorizontalAlign = HorizontalAlign.Left
' headerText = gwResult.HeaderRow.Cells(i).Text
' If headerText = "Description" Then
' desc = i
' 'Else
' ' gwResult.HeaderRow.Cells(i).Width = 75
' End If
' Next
'For Each row As GridViewRow In Me.gwResult.Rows
' 'row.Cells(desc).CssClass = "gwStyle"
' For i As Integer = 0 To headCell - 1
' If IsNumeric(row.Cells(i).Text) Then
' row.Cells(i).HorizontalAlign = HorizontalAlign.Right
' End If
' Next
'Next

Resources