``` f_upca(upc )```power builder里这个条码compute expression是什么意思
时间: 2024-06-17 19:07:21 浏览: 7
在PowerBuilder中,compute expression是计算表达式的意思。`f_upca(upc)`是一个自定义函数,用于将UPC码转换为UPC-A码,其中`upc`是UPC码。在该compute expression中,可以使用该函数来计算UPC码对应的UPC-A码。该计算表达式可能用于数据窗口或报表中的条码显示。
相关问题
用c#校验UPC条码是否正确
UPC条码一共有两种格式:UPC-A和UPC-E,它们的校验算法略有不同。下面分别介绍它们的校验方法。
UPC-A 校验:
UPC-A码由12位数字组成,其中最后一位是校验位。校验位的计算方法如下:
1. 将第1、3、5、7、9、11位数字相加。
2. 将第2、4、6、8、10位数字相加。
3. 将第1步的结果乘以3,然后加上第2步的结果。
4. 取结果的个位数(即结果模10的余数),然后用10减去该数,得到的数就是校验位。
下面是用 C# 实现 UPC-A 校验的代码:
```csharp
public bool VerifyUPCA(string code)
{
if (code.Length != 12 || !Regex.IsMatch(code, @"^\d{12}$"))
return false;
int evenSum = 0, oddSum = 0;
for (int i = 0; i < 12; i++)
{
int digit = int.Parse(code[i].ToString());
if (i % 2 == 0)
oddSum += digit;
else
evenSum += digit;
}
int totalSum = evenSum * 3 + oddSum;
int checkDigit = (10 - totalSum % 10) % 10;
return checkDigit == int.Parse(code[11].ToString());
}
```
UPC-E 校验:
UPC-E码由6、7、8位数字组成,其中最后一位是校验位。在进行校验之前,需要将UPC-E码转换为UPC-A码。转换的过程如下:
1. 如果UPC-E码的第1位是0、1、2,则将UPC-E码的第7、8位分别设为0、1、2,然后将前5位和第7、8位组成一个UPC-A码。
2. 如果UPC-E码的第1位是3,则将UPC-E码的第7、8位分别设为0、3,然后将前5位和第7、8位组成一个UPC-A码。
3. 如果UPC-E码的第1位是4,则将UPC-E码的第7、8位分别设为0、4,然后将前5位和第7、8位组成一个UPC-A码。
4. 如果UPC-E码的第1位是5、6、7、8、9,则将UPC-E码的第7位设为0,然后将前6位和第7、8位组成一个UPC-A码。
转换为UPC-A码之后,就可以使用UPC-A码的校验方法进行校验了。下面是用 C# 实现 UPC-E 校验的代码:
```csharp
public bool VerifyUPCE(string code)
{
if (code.Length != 6 && code.Length != 7 && code.Length != 8 || !Regex.IsMatch(code, @"^\d{6,8}$"))
return false;
string upca = "";
switch (code[0])
{
case '0':
case '1':
case '2':
upca = code.Substring(0, 3) + "00" + code.Substring(3, 2) + code[0];
break;
case '3':
upca = code.Substring(0, 3) + "00" + code.Substring(3, 2) + "3";
break;
case '4':
upca = code.Substring(0, 3) + "00" + code.Substring(3, 2) + "4";
break;
default:
upca = code.Substring(0, 4) + "0" + code.Substring(4, 2);
break;
}
return VerifyUPCA(upca);
}
```
java生成可以自定义宽高的条形码
可以使用ZXing库来生成自定义宽高的条形码。以下是一个示例代码:
```java
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.imageio.ImageIO;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.oned.Code128Writer;
import com.google.zxing.oned.EAN13Writer;
import com.google.zxing.oned.UPCAWriter;
public class BarCodeGenerator {
public static void main(String[] args) throws IOException, WriterException {
String text = "123456789012"; // 条形码内容
// 生成 Code128 条形码
code128(text, 200, 50, "code128.png");
// 生成 EAN13 条形码
ean13(text, 200, 100, "ean13.png");
// 生成 UPCA 条形码
upca(text, 200, 100, "upca.png");
}
/**
* 生成 Code128 条形码
*/
public static void code128(String text, int width, int height, String filePath)
throws IOException, WriterException {
Code128Writer writer = new Code128Writer();
BitMatrix bitMatrix = writer.encode(text, BarcodeFormat.CODE_128, width, height);
BufferedImage image = MatrixToImageWriter.toBufferedImage(bitMatrix);
ImageIO.write(image, "png", new File(filePath));
}
/**
* 生成 EAN13 条形码
*/
public static void ean13(String text, int width, int height, String filePath)
throws IOException, WriterException {
EAN13Writer writer = new EAN13Writer();
BitMatrix bitMatrix = writer.encode(text, BarcodeFormat.EAN_13, width, height);
BufferedImage image = MatrixToImageWriter.toBufferedImage(bitMatrix);
ImageIO.write(image, "png", new File(filePath));
}
/**
* 生成 UPCA 条形码
*/
public static void upca(String text, int width, int height, String filePath)
throws IOException, WriterException {
UPCAWriter writer = new UPCAWriter();
BitMatrix bitMatrix = writer.encode(text, BarcodeFormat.UPC_A, width, height);
BufferedImage image = MatrixToImageWriter.toBufferedImage(bitMatrix);
ImageIO.write(image, "png", new File(filePath));
}
}
```
在上面的代码中,我们使用了`Code128Writer`、`EAN13Writer`和`UPCAWriter`类来分别生成 Code128、EAN13 和 UPCA 条形码。这些类都可以接受一个自定义的宽度和高度参数。我们使用`BufferedImage`和`ImageIO`类将`BitMatrix`对象转换为 PNG 格式的图片,并保存到指定的文件路径。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)