- Convert A Alphanumeric String Into A Serial Keys
- Convert A Alphanumeric String Into A Serial Keyboard
- Convert A Alphanumeric String Into A Serial Key
- Convert A Alphanumeric String Into A Serial Key For Battlefield 1
- Convert A Alphanumeric String Into A Serial Key For Windows 10
- Convert A Alphanumeric String Into A Serial Key Generator
- Convert A Alphanumeric String Into A Serial Key Code
CONVERT (WS) File/Directory Functions. CINT (VBA) CLNG (VBA) CSNG (VBA) CSTR (VBA) CVAR (VBA) MS Excel: How to test a string for an alphanumeric value. This Excel tutorial explains how to test for an alphanumeric value (with screenshots and step-by-step instructions). The AlphaNumeric function will return TRUE if all of the.
- Alphanumeric Autonumber Primary Key Oct 26, 2004. How To Convert Alphanumeric With Symbols To INT Jun 5, 2015. I am new to SSC. I have a table that has NO.OF WORKING HOURS for 30 days. I know how to find non alphanumeric chars in a string but not sure if I can how to find the strings with minimum 2 non alphanumeric chars?
- Remove non alphanumeric characters. The String class represents character strings. Strings are constant, their values cannot be changed after they are created. Alpha stands for alphabets and numeric stands for number. String to Integer, Convert String to DateTime How to strip non-alphanumeric characters C# VB.Net. Output: helloworld100010.
Active6 years, 9 months ago
I'm having an issue with PySerial and Python (3.3): The code I'm running (for now, this is just a simple test case) is as follows:
which gives the following error:
What's my stupid mistake? I think I've traced this to the fact that PySerial's readline is returning a binary string (new in python 3?) and that the string operation 'split' is failing when run against a binary string - it works fine if you run this:
Which gives the expected:
But then running:
gives the error above. Is there a different readline method to use? should I code my own with read (and just read until it sees /r/n) or can I easily convert to a string that will satisfy str.isalnum()? Thanks!
dsolimano7,60733 gold badges4141 silver badges5757 bronze badges
Sam.T.PrattSam.T.Pratt
1 Answer
The quickest solution will be to use a python module called binascii that has a selection of functions for converting the binary string to an ascii string: http://docs.python.org/2/library/binascii.html
EDIT:The b means that it is a byte array and not a literal string. The correct way to convert the byte array to a litteral string will be to use the str() function:
str(b'1234, asdf, 456, jkl', 'ascii').split(',')
this gives the output you want:['1234', 'asdf', '456', jkl']
I hope that helps!
EnthralEnthral
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Not the answer you're looking for? Browse other questions tagged stringserial-portpyserialpython-3.3 or ask your own question.
Here are several techniques for creating serial numbers, then you already know how to filter the unwanted ones outOne common question on the newsgroups is 'how do I increment a number in my sheet each time I use it', whether it's an invoice, an order form, or some other numbered form. There are a number of factors to take into account . For instance, whether the current number is saved locally or on a server, or whether more than one person will access a number at a time, or only a single user.
Two ways explored here. It is assumed that the sequential numbers should be stored locally, and that only one number at a time is accessed. The first is to use the registry (and yes, Macs use the equivalent of a registry - the values are stored in file(s) in the Preferences folder). The second uses a text file to store the relevant data. For simplicity I'll assume that an invoice is generated from a template with the following layout:.
Using the registry to hold sequential numbers An advantage of the registry is that the numbers are unlikely to be inadvertently modified or deleted. A significant disadvantage is that the registry is not designed as a database, which can retain a history, but rather is more suited to storage of a single record. Information is stored in the registry using the SaveSetting method, and retrieved using the GetSetting method. This macro, put in a template's ThisWorkbook code module, will produce an incremented sequential number each time the template is used to generate a document:
Private Sub Workbook_Open()
Const sAPPLICATION As String = 'Excel'
Const sSECTION As String = 'Invoice'
Const sKEY As String = 'Invoice_key'
Const nDEFAULT As Long = 1&
Dim nNumber As Long
With ThisWorkbook.Sheets('Invoice')
With .Range('B1')
If IsEmpty(.Value) Then
.Value = Date
.NumberFormat = 'dd mmm yyyy'
End If
End With Serial key generator.
With .Range('B2')
If IsEmpty(.Value) Then
nNumber = GetSetting(sAPPLICATION, sSECTION, sKEY, nDEFAULT)
.NumberFormat = '@'
.Value = Format(nNumber, '0000')
SaveSetting sAPPLICATION, sSECTION, sKEY, nNumber + 1&
End If
End With
End With
End Sub
Using a text file to hold sequential numbers This method is more useful in some situations. The biggest advantage is that the sequential number is no longer tied to a particular machine - it can be stored on a common server, or even a thumb drive. Disadvantages include difficulty in keeping the file from being modified simultaneously by two users, or of the file being more easily deleted or modified. This function will return the next sequential number:
Public Function NextSeqNumber(Optional sFileName As String, Optional nSeqNumber As Long = -1) As Long
Const sDEFAULT_PATH As String = '<your path here>'
Const sDEFAULT_FNAME As String = 'defaultseq.txt'
Dim nFileNumber As Long
nFileNumber = FreeFile
If sFileName = ' Then sFileName = sDEFAULT_FNAME
If InStr(sFileName, Application.PathSeparator) = 0 Then _
sFileName = sDEFAULT_PATH & Application.PathSeparator & sFileName
If nSeqNumber = -1& Then
If Dir(sFileName) <> ' Then
Open sFileName For Input As nFileNumber
Input #nFileNumber, nSeqNumber
nSeqNumber = nSeqNumber + 1&
Close nFileNumber
Else
nSeqNumber = 1&
End If
End If
On Error GoTo PathError
Open sFileName For Output As nFileNumber
On Error GoTo 0
Print #nFileNumber, nSeqNumber
Close nFileNumber
NextSeqNumber = nSeqNumber
Exit Function
PathError:
NextSeqNumber = -1&
End Function
If you provide a full path in sFileName, that's where the file will be stored. If not, the file will be stored in whatever default directory you specify. You can set the sequential number by providing a value for nSeqNumber.
Thus, if I'm only using one sequence I can use
Public Sub Workbook_Open()
ThisWorkbook.Sheets(1).Range('B2').Value = NextSeqNumber
End Sub
to return the next sequence number. If I'm using multiple sequences, I include the filename (with path, if the text file is not in the default path).
Public Sub NewClientInvoice()
ThisWorkbook.Sheets(1).Range('B2').Value = NextSeqNumber('Client1.txt')
End Sub
And if I want to start a new sequence, beginning at, say, 1001, include that number in the function call. If the client name were in cell B4:
Public Sub SetUpNewClient()
With ThisWorkbook.Sheets(1)
.Range('B2').Value = NextSeqNumber(.Range('B4').Value & '.txt', 1001)
End With
End Sub
This page last updated Thursday, 28 April 2005
Use Registry for Serial Numbers – take 2 One method........save a sequential number in the Registry then when you open a new workbook from the Template it is immediately saved as template name + sequential number pulled from the Registry
Example code for Thisworkbook module of an Excel template named MyTemplate.
NOTE: MyTemplate must be saved as macro-enabled template (*.xltm)
Convert A Alphanumeric String Into A Serial Keys
Private Sub Workbook_Open()
Const sAPPLICATION As String = 'Excel'
Const sSECTION As String = 'MyTemplate'
Const sKEY As String = 'MyTemplate_key'
Const nDEFAULT As Long = 1&
Dim nNumber As Long
nNumber = GetSetting(sAPPLICATION, sSECTION, sKEY, nDEFAULT)
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs sSECTION & Format(nNumber + 1&, '_0000')
Application.DisplayAlerts = True
SaveSetting sAPPLICATION, sSECTION, sKEY, nNumber + 1&
End Sub
Const sAPPLICATION As String = 'Excel'
Const sSECTION As String = 'MyTemplate'
Const sKEY As String = 'MyTemplate_key'
Const nDEFAULT As Long = 1&
Dim nNumber As Long
nNumber = GetSetting(sAPPLICATION, sSECTION, sKEY, nDEFAULT)
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs sSECTION & Format(nNumber + 1&, '_0000')
Application.DisplayAlerts = True
SaveSetting sAPPLICATION, sSECTION, sKEY, nNumber + 1&
End Sub
The first new workbook will be saved as Excel workbook MyTemplate_0001.xlsx then increment from there.....probably no need to have it as macro-enabled. If you did need the copy saved as macro-enabled post back for revised code to saveas macro-enabled and prevent Workbook_Open from running when copies are opened later for review.
Generating Unique Numbers for Worksheets – Serial NumberSummary: You may need to automatically generate unique numbers when you create new worksheets in a workbook. Here's a couple of easy ways to do it. (This tip works with Microsoft Excel 97, Excel 2000, Excel 2002, Excel 2003, and Excel 2007.)
Sometimes you may need Excel to generate a unique number for your worksheets. For instance, you could be using Excel to create forms such as invoices, statements, or tracking sheets, and you need an unique numbers for each form (I'll call this a ticket number). This, of course, implies that Excel needs to remember the number from one session to the next.
There are a couple of ways you can approach this problem. If the numbers don't need to be sequential, you could create a ticket number based on the current time of day, in seconds. The following macro can be added to the ThisWorksheet object:
Private Sub Workbook_NewSheet(ByVal Sh As Object)
Dim lTicket As Long
lTicket = CLng(Time * 24 * 60 * 60)
Sh.Range('A1') = lTicket
End Sub
The macro is triggered every time a new worksheet is added to the workbook. It takes the current time, converts it to an integer number of seconds, and then places that value into cell A1. The likelihood of duplicating ticket numbers within any given day is remote, but it could happen over time. (For instance, if you create a ticket at the exact same time today that you did yesterday or last week.)
To get around this problem, you could create a ticket number in the following manner:
Private Sub Workbook_NewSheet(ByVal Sh As Object)
Dim sTemp As String
Convert A Alphanumeric String Into A Serial Keyboard
sTemp = Format(Date, 'yymmdd') & Format(Time, 'hhmmss')
Convert A Alphanumeric String Into A Serial Key
Sh.Range('A1') = sTemp
End Sub
This version of the event handler constructs a ticket number based both the date and time. Unless you are creating trouble tickets very quickly, this approach should reduce the possibility of duplicate numbers generated by the macro.
If the numbers must be sequential within the current workbook, then you can define a name that contains the current high value of your ticket number, and then a macro that places that number in a cell on a new worksheet and increments the value of the stored number. Follow these steps to start:
- Choose Name from the Insert menu, then choose Define. Excel displays the Define Name dialog box. (Click here to see a related figure.) (To display the equivalent dialog box in Excel 2007, display the Formulas tab of the ribbon and then click on Define Name in the Defined Names group. Excel displays the New Name dialog box.)
- In the Name box, enter a name such as MaxNum.
- In the Refers To area at the bottom of the dialog box, enter an equal sign followed by the value you want used for the next ticket number.
- Click on OK. The new name is stored in the workbook.
Now, add the following macro to the ThisWorksheet object in the VBA Editor:
Private Sub Workbook_NewSheet(ByVal Sh As Object)
Dim iMax As Integer
iMax = Mid(ThisWorkbook.Names('MaxNum'), 2)
Convert A Alphanumeric String Into A Serial Key For Battlefield 1
Sh.Range('A1') = iMax
iMax = iMax + 1
Convert A Alphanumeric String Into A Serial Key For Windows 10
ThisWorkbook.Names('MaxNum').RefersTo = '=' & iMax
End Sub
Convert A Alphanumeric String Into A Serial Key Generator
This macro is executed every time you insert a new worksheet in the workbook. It retrieves the value you stored in the MaxNum, places that value into cell A1 of the new worksheet, and then increments what is stored in MaxNum.